forked from tiann/markdown-img-upload
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipboard.py
34 lines (28 loc) · 1013 Bytes
/
clipboard.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
# -*- coding: utf-8 -*-
import time
from AppKit import NSPasteboard, NSPasteboardTypePNG, NSPasteboardTypeTIFF, NSPasteboardTypeString
def get_paste_img_file():
pb = NSPasteboard.generalPasteboard()
data_type = pb.types()
# if img file
print data_type
now = int(time.time() * 1000) # used for filename
if NSPasteboardTypePNG in data_type:
# png
data = pb.dataForType_(NSPasteboardTypePNG)
filename = '%s.png' % now
filepath = '/tmp/%s' % filename
ret = data.writeToFile_atomically_(filepath, False)
if ret:
return filepath
elif NSPasteboardTypeTIFF in data_type:
# tiff
data = pb.dataForType_(NSPasteboardTypeTIFF)
filename = '%s.tiff' % now
filepath = '/tmp/%s' % filename
ret = data.writeToFile_atomically_(filepath, False)
if ret:
return filepath
elif NSPasteboardTypeString in data_type:
# string todo, recognise url of png & jpg
pass