Freddie February 2016

AppleScript - Change all app icons in a directory

I have folders containing applications. I want to be able to select the folder with an apple script, and have the script go through each app file in that directory, changing the icons for me.

I want to have the icon set from an image stored in the script directory.

I'd really appreciate any help because I've been trying to make this work for a while. This is my progress so far:

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

Answers


pbell February 2016

The script bellow does now what you want. As explained before, your icon file must be type icns. I now add this filter directly in the choose file command.

The selected icon will now replace ALL icons already in each Contents/Resources folder of all applications in the selected folder. The replacement will be done preserving the name of the icns already in place.

Warning : there is no 'undo' command. your old icons are overwritten !!

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

Post Status

Asked in February 2016
Viewed 2,497 times
Voted 8
Answered 1 times

Search




Leave an answer