I have written a couple of scripts for a friend, and I was wondering if I could assign an icon to application as part of the install process? I have searched to forum, but found nothing so far. Here is what I want to do:
tell application "Script Editor"
--open the script I wrote (it is on a JumpDrive)
--save it to the desktop as an application
end tell
--set the icon of [application] to SOMETHING
I cannot find anything in new AS dictionary either. I have looked at the Finder, System Events, and Image Events dictionaries.
Thanks
Craig Smith
Model: Powermac dual G4
AppleScript: 2.1
Browser: Firefox 1.0
Operating System: Mac OS X (10.4)
I believe you, but I cannot see how that works. There is nothing in the dictionary about how to include an icon file, nor do I see the option when I choose Save As directly from Script Editor. Do you know how to do it?
After you’ve saved the script as an application bundle, click Bundle Resources, then replace the default icon. It’s easier if you use the same name. (If you script has an “on open” handler, the icon will likely be named “droplet” instead of “applet.”)
If you need to make an .icns file, use the Icon Composer app included with the developer tools (or use third-party software).
Note that you can also navigate to the app’s resources in Finder by right clicking the app bundle and choosing Show Package Contents.
Perhaps this script (from Pantechnicon) may help you:
Change Folder Icon
Change icon of a folder to icon of a particilar file, using AppleScript.
on changeIcon()
set rslt to ""
tell application "Finder"
try
choose file with prompt ¬
"Choose the file whose icon you want to copy."
set newIcon to icon of the result
choose folder with prompt ¬
"Choose folder whose icon you want to change."
set folderName to the result as alias
set the icon of folderName to newIcon
on error errMsg
set rslt to errMsg
end try
end tell
return rslt
end changeIcon
The last few posts in that therad discuss a couple other methods. One that I posted uses gui scripting to copy/paste an icon from one item to another. Note that this is potentially fragile code… as all gui scripting is. It also only changes the local file’s icon, and may not survive copying or archiving (like if you move it from one machine to another, or if you try to zip it and send it to someone else). The second method changes the actual resource of the file to a new image. Note: I think image capture scripting, discussed in this method, is now part of the image events so you may need to account for this.
If you’re using ‘application bundle’ scripts, another method would be to manually change the icon of the bundle. By default it’s got a generic system “applet” or “droplet” icon, which you can easily change. You’ll need to furnish a copy of your desired icns file, but it would be really easy to rename or add the new icns file to the resources of the bundle. As Bruce Phillips said, in the script bundle, at the path “/Contents/Resources/applet.icns” is the generic icon for the script. You could copy your icon to this folder and name it the same as the original, and it will become your script’s icon. Or, you could add any other icns file you want to this location, and then change your info.plist’s “CFBundleFileIcon”? entry to the name of the icon you placed in the directory.