Skip to content

Commit f99bf50

Browse files
committed
Allow passing extension to pb
1 parent a41814a commit f99bf50

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<key>config</key>
107107
<dict>
108108
<key>argumenttype</key>
109-
<integer>2</integer>
109+
<integer>1</integer>
110110
<key>keyword</key>
111111
<string>pb</string>
112112
<key>subtext</key>
@@ -131,7 +131,7 @@
131131
<key>escaping</key>
132132
<integer>102</integer>
133133
<key>script</key>
134-
<string>python upload-s3.py "text"</string>
134+
<string>python upload-s3.py "text" {query}</string>
135135
<key>scriptargtype</key>
136136
<integer>0</integer>
137137
<key>scriptfile</key>

upload-s3.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
def get_random_bit(length):
1818
return ''.join(random.SystemRandom().choice(string.ascii_lowercase + string.ascii_uppercase + string.digits) for _ in range(length))
1919

20-
def capture_text():
20+
def capture_text(extension):
2121
# global name 'subprocess' is not defined
2222
text_file = subprocess.check_output("pbpaste", shell=True)
2323
random_bit = get_random_bit(10)
24-
file_name = 'clip-'+random_bit+'.txt'
24+
file_name = 'clip-'+random_bit+'.'+extension
2525
file_path = os.path.join(tempfile.mkdtemp(), file_name)
2626
with open(file_path, "wb") as f:
2727
f.write(text_file)
28-
return file_path, file_name, 'text/plain'
28+
# return content type based on extension.
29+
content_type = mimetypes.MimeTypes().guess_type(file_path)[0]
30+
return file_path, file_name, content_type
2931

3032
def capture():
3133
random_bit = get_random_bit(5)
@@ -54,9 +56,15 @@ def capture():
5456

5557
def main(wf):
5658
import boto3
59+
# print all arguments for debug.
60+
#for arg in sys.argv:
61+
# print (arg)
62+
#exit()
5763
# if cmd is pressed we assume it is text capture.
5864
if sys.argv[1] == "text":
59-
file_path, file_name, content_type = capture_text()
65+
# extension in 2nd argument
66+
extension = sys.argv[2] if len(sys.argv) > 2 else 'txt'
67+
file_path, file_name, content_type = capture_text(extension)
6068
else:
6169
file_path, file_name, content_type = capture()
6270
account_id = os.getenv('cf_account_id')

0 commit comments

Comments
 (0)