-
Notifications
You must be signed in to change notification settings - Fork 4
/
save_script.py
40 lines (36 loc) · 1.14 KB
/
save_script.py
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
''' This script allows you to copy a .py script to the iOS clipboard and then use Open In...
to have that script saved in Pythonista. This requires both the Workflow and Pythonista apps
and the workflow at https://workflow.is/workflows/8cdee57f79664205a6a565c9cbdb3d48 '''
import clipboard
import console
import os
import sys
def save(filename, text, ext):
root, _ = os.path.splitext(filename)
extension = ext
filename = root + extension
filenum = 1
while os.path.isfile(filename):
filename = '{} {}{}'.format(root, filenum, extension)
filenum += 1
#print(finalname)
with open(filename,'w') as f:
f.write(text)
#clipboard.set(filename)
return filename
def main():
resp = console.alert('Alert!', 'Choose File Extension', '.py', '.pyui', hide_cancel_button=False)
if resp==1:
ext = '.py'
elif resp==2:
ext = '.pyui'
text = clipboard.get()
assert text, 'No text on the clipboard!'
filename = sys.argv[1]
console.clear()
print('Wait a Moment Please!')
filename = save(filename, text, ext)
console.set_font('Futura', 16)
print('Done!\nFile Saved as:\n' + filename)
if __name__ == '__main__':
main()