如何找到并复制(到剪贴板)文件夹中的最新文件?
这是文件夹的路径:
/Users/myuser/Desktop/Screenshots
答案 0 :(得分: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)