2013-03-24 99 views
0

出于组织目的,通过热键,我希望能够快速复制选定的图像文件(如Finder中所示),然后将其粘贴为所选文件夹的图标,而不必进入该文件夹的“获取信息”。Applescript - 复制图像,粘贴为图标

这可能吗?

回答

0

您可能需要两个脚本:一个复制图像(不是文件,而是图像本身),另一个将图像粘贴为图标。
复制图像:

tell application "Finder" 
    open selection using (path to application "Preview") -- open with Preview 
end tell 

tell application "Preview" 
    tell application "System Events" 
     keystroke "a" using command down -- select all 
     keystroke "c" using command down -- copy 
     keystroke "w" using command down -- close window 
    end tell 
end tell 

粘贴图片作为图标:

tell application "Finder" 
    activate 
    tell application "System Events" 
     keystroke "i" using command down -- open info 

     -- set focus on icon image 
     tell process "Finder" 
      set img to (image 1 of scroll area 1 of front window) 
      set focused of img to true 
     end tell 

     keystroke "v" using command down -- insert image 
     keystroke "w" using command down -- close window 
    end tell 
end tell 

比你可以在这两个脚本绑定到一些快捷键。我为此使用FastScripts。

注1:您可能需要启用SystemPreferences下辅助设备的控制 - >辅助
注2:如果脚本的某些部分没有(例如预览打开工作,但没有选择图像等),你应该尝试玩延迟。