简体   繁体   English

Applescript-复制图像,粘贴为图标

[英]Applescript - Copy Image, Paste as Icon

For organizational purposes, via a hotkey, I'd like to be able to quickly copy a selected image file (as is in Finder), then paste it as the icon for a selected folder, without having to go into 'Get Info' for the folder. 出于组织目的,我希望能够通过热键快速复制选定的图像文件(如Finder中一样),然后将其粘贴为选定文件夹的图标,而无需进入“获取信息”文件夹。

Is this possible? 这可能吗?

You probably need two scripts: one to copy image (not a file but image itself), other to paste image as icon. 您可能需要两个脚本:一个用于复制图像(不是文件而是图像本身),另一个用于将图像粘贴为图标。
Copy image: 复制图片:

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

Paste image as icon: 将图片粘贴为图标:

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

Than you can bind these two scripts to some hotkeys. 比您可以将这两个脚本绑定到一些热键。 I use FastScripts for that purpose. 我为此使用FastScripts。

Note 1 : you may need to enable access for assistive devices under the SystemPreferences -> Accessibility 注意1 :您可能需要在SystemPreferences-> Accessibility下启用辅助设备的访问
Note 2 : if some parts of the scripts are not work (for example Preview opened, but image not selected, etc.) you should try to play with delays. 注意2 :如果脚本的某些部分不起作用(例如,打开了预览,但未选择图像等),则应尝试延迟播放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM