2017-02-09 33 views

回答

2

試試這個:

tell application "Finder" to set theFiles to sort (get files of folder "Screenshots" of desktop) by creation date 
set the clipboard to last item of theFiles as alias 

要將圖像複製到純粹的AppleScript剪貼板很麻煩。這是很容易用幾行AppleScriptObjC:

use framework "Foundation" 

tell application "Finder" to set theFiles to sort (get files of folder "Screenshots" of desktop) by creation date 
set imageFile to last item of theFiles as text 
set theData to current application's NSData's dataWithContentsOfFile:(POSIX path of imageFile) 
set pasteBoard to current application's NSPasteboard's generalPasteboard() 
pasteBoard's clearContents() 
pasteBoard's setData:theData forType:(current application's NSPasteboardTypeTIFF) 
+0

這似乎爲我的剪貼板中得到什麼也沒有抹去做一些事情。但該圖像未設置在剪貼板中。 – unska

+0

對不起! – unska

+0

你寫了*複製(剪貼板)最近的文件*,而不是文件的**內容**。要複製圖像,您需要AppleScriptObjC(Cocoa)的一些幫助。我更新了答案。 – vadian

相關問題