Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否使用AppleScript更改文件夹的图标?_Applescript - Fatal编程技术网

是否使用AppleScript更改文件夹的图标?

是否使用AppleScript更改文件夹的图标?,applescript,Applescript,我已经创建了一个AppleScript,它对我很有帮助,我希望它能自动更改文件夹图标 这个脚本非常简单,它创建一个文件夹,然后在同一个文件夹中创建一个空文本文件 以下是脚本: 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"

我已经创建了一个AppleScript,它对我很有帮助,我希望它能自动更改文件夹图标

这个脚本非常简单,它创建一个文件夹,然后在同一个文件夹中创建一个空文本文件

以下是脚本:

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
是否可以自动更改文件夹图标


(我的自定义文件夹图标(.icns)当然与脚本位于同一文件夹中)

这里有一个解决方案,它使用此软件包中的命令行实用程序“seticon”:

它的工作原理是假设您的脚本、icns文件和新文件夹都在同一个目录中

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

谢谢你的帮助!要使其正常工作,我必须使用脚本自动复制并粘贴父文件夹中的.icns文件,是否可能?当然没有问题,或者您可以将.icns保留在固定位置,只需使用绝对路径即可。tell中的前3行只是处理路径,do shell脚本是关键部分,您可以将任何需要的路径传递给它。非常感谢!(参见我的个人资料,关于Applescript;-)的另一个问题)项目链接已断开。这似乎是同一个: