Skip to content

Instantly share code, notes, and snippets.

Last active Jan 27, 2016
What would you like to do?
# coding: utf-8
''' 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 either of the following Workflows:
Save in Pythonista (from Workflow Action Extension)
Open in Pythonista (from Document Picker)
Adapted from: '''
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
with open(filename,'w') as f:
return filename
def main():
#print sys.argv[:]
filename = sys.argv[1]
resp = console.alert(
'Choose File Extension',
'Detect Extension'+' (.'+sys.argv[2]+')',
if resp==1:
ext = '.'+sys.argv[2]
elif resp==2:
ext = '.py'
elif resp==3:
ext = console.input_alert('File extension', 'Type a file extension.', '.')
if len(sys.argv) > 3:
text = sys.argv[3]
elif clipboard.get():
text = clipboard.get()
#console.alert('Used clipboard')
assert text, 'No text captured!'
print('Wait a Moment Please!')
filename = save(filename, text, ext)
print('Done!\nFile Saved as:\n' + filename)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment