AppleScript - 更改目录中的所有应用程序图标

时间:2016-02-08 20:09:17

标签: applescript

我有包含应用程序的文件夹。我希望能够选择带有苹果脚本的文件夹,并让脚本浏览该目录中的每个应用程序文件,为我更改图标。

我希望从存储在脚本目录中的图像中设置图标。

我非常感谢任何帮助,因为我已经尝试过这项工作一段时间了。这是我目前的进展:

property appcurrentCount : 0
on run
set theFolder to (choose folder with prompt "Select the start folder")
doSomethingWith(theFolder)
end run
on doSomethingWith(aFolder)
tell application "Finder"
 set subApps to every file of aFolder
 repeat with eachFolder in subApps

-- replace icon here somehow

 end repeat
end tell

display dialog "Count is now " & appcurrentCount & "."
end doSomethingWith

1 个答案:

答案 0 :(得分:0)

下面的脚本现在可以满足您的需求。如前所述,您的图标文件必须是icns类型。我现在直接在choose file命令中添加此过滤器。

现在,所选图标将替换所选文件夹中所有应用程序的每个“内容/资源”文件夹中已有的所有图标。 替换将完成,保留已经存在的icns的名称。

警告:没有'撤消'命令。你的旧图标被覆盖!!

set Myicon to choose file with prompt "Select Icns to be copied in every Application of the folder" of type "com.apple.icns"
set MyFolder to choose folder with prompt "Select the folder with all applications to be changed"
set Source to POSIX path of Myicon -- convert path to unix form

tell application "Finder"
set MyApps to every item of MyFolder whose name extension is "app"
display dialog "count apps=" & count of MyApps
repeat with anAps in MyApps -- loop for each App
    set IcnFolder to ((anAps as string) & ":Contents:Resources:") as alias
    set MyIcns to (every item of IcnFolder whose name extension is "icns")
    display dialog "count of icn in " & alaps & " = " & (count of MyIcns)
    repeat with oneIcon in MyIcns -- loop for each icns
set Destination to POSIX path of (oneIcon as string)
        try
            do shell script "cp " & (quoted form of Source) & " " & (quoted form of Destination)
        end try
    end repeat -- loop for each icns
end repeat -- loop for each App
end tell