-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture.py
More file actions
executable file
·57 lines (44 loc) · 1.03 KB
/
capture.py
File metadata and controls
executable file
·57 lines (44 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/python
import os
import time
import sys
def sort_filename(a, b):
try:
a_num = int(a.split('.')[0].split('-')[-1])
except:
return -1
try:
b_num = int(b.split('.')[0].split('-')[-1])
except:
return 1
if a_num == b_num:
return 0
elif a_num < b_num:
return -1
else:
return 1
try:
directory = sys.argv[1]
except:
print 'Please specify a directory for this capture session'
exit()
# Find latest image number
files = os.listdir(directory)
if len(files) == 0:
count = 1
else:
files.sort(sort_filename)
count = files[-1].split('.')[0].split('-')[-1]
if count == '':
count = 1
else:
count = int(count) + 1
print "Starting image capture from #%d" % count
name = 'screenshot'
delay = 5
while True:
filename = "%s/%s-%i.png" % (directory.rstrip('/'), name, count)
os.system("screencapture -x %s" % filename)
print "Captured screenshot #%i" % count
count = count + 1
time.sleep(delay)