Change icon of folder with AppleScript?

偶尔善良 提交于 2019-12-21 21:25:27

问题


i've create an AppleScript very helpful to me and i wish if it is possible to automatically change the folder icon.

This script is very simple, it create one folder, then create one empty text file in the same folder.

Here is the script:

tell application "Finder"
    set newfolder to make new folder with properties {name:My Folder}
    make new file at newfolder with properties {name:"read_me.txt"}
end tell

Is it possible to automatically change the folder icon?

(I own my custom folder icon (.icns) in the same folder as the script, of course)


回答1:


Heres a solution that uses a command line utility "seticon" found in this package: https://github.com/vasi/osxutils

It works on the assumption your script, icns file and new folder are all in the same directory.

tell application "Finder"
    set parent_path to ((the container of the (path to me)) as text)
    set target_folder_path to quoted form of POSIX path of (parent_path & "my folder")
    set icon_path to quoted form of POSIX path of (parent_path & "icon.icns")
    do shell script "/usr/local/bin/seticon -d " & icon_path & " " & target_folder_path
end tell


来源:https://stackoverflow.com/questions/20172959/change-icon-of-folder-with-applescript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!