2017-02-09 8 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