hi, I’m looking for a way to set a specific icon to a specific files produced regularly.
I thought of placing an Automator Application on toolbar allowing a quick drag to set this custom icon…
The script would refer to a .icns file stored locally.
I wrote you a small AppleScript droplet named Ionic Elf, which sets a defined image as the icon of dropped files. You can chose the image by opening the script with a double click. To set the chosen image as the icon for a bunch of files, just drop them onto the script afterwards.
The script is based on a simple command line tool I wrote today, you can study its source code here.
To download the ready for use droplet, just click here, its only a small download (ca. 50 KB).
Please note that the script requires Mac OS X 10.5 or higher.
Maybe you can make good use of it.
Best regards from snow Berlin,
Martin
-- author: Martin Michel
-- eMail: martin@joyofscripting.com
-- created: 27.01.2010
-- version: 1.0
-- This script sets the icon of dropped files to the defined image.
-- The image can be chosen by opening the script with a double click.
property mytitle : "Ionic Elf"
property imgfilepath : missing value
-- I am called when the user opens the script with a double click
on run
set imgfilepath to (choose file with prompt "Please select an image to be used as a file icon:" without invisibles, multiple selections allowed and showing package contents) as text
end run
-- I am called when the user drops Finder items onto the script's icon
on open finderitems
try
-- did the user already chose an image to be used as a file icon?
if imgfilepath is missing value then
run
end if
-- if so, does it still exist?
if not my itempathexists(imgfilepath) then
run
end if
-- searching for files in the dropped Finder items
set foundfiles to {}
repeat with finderitem in finderitems
set finderiteminfo to (info for finderitem)
if not folder of finderiteminfo then
set foundfiles to foundfiles & finderitem
end if
end repeat
-- no files found :(
if foundfiles is {} then
set errmsg to "Please drop some files (not folders) onto the script to change their icon."
my dsperrmsg(errmsg, "--")
return
end if
-- processing each found file with the command line tool
set qtdtoolpath to quoted form of POSIX path of (((path to me) as text) & "Contents:Resources:ionicelf")
repeat with foundfile in foundfiles
set command to qtdtoolpath & " -img " & quoted form of POSIX path of imgfilepath & " -file " & quoted form of POSIX path of foundfile
try
do shell script command
on error errmsg number errnum
my dsperrmsg(errmsg, errnum)
end try
end repeat
end try
end open
-- I am indicating if a given item path exists
on itempathexists(itempath)
try
set itemalias to itempath as alias
return true
on error
return false
end try
end itempathexists
-- I am displaying error messages to the user
on dsperrmsg(errmsg, errnum)
tell me
activate
display dialog "Sorry, an error occurred:" & return & return & errmsg & " (" & errnum & ")" buttons {"OK"} default button 1 with icon stop with title mytitle
end tell
end dsperrmsg
Oh, how I envy you for living in hot Western Australia It’s currently freezing cold here in Germany, with a lots of snow and ice everywhere. My wife already suggested a trip to Tenerife to escape the cold, but we have both too many work projects…And of course, my little daughter loves the weather, she likes to go sledding with daddy :lol:
Actually the script should process every image format supported by NSImage:
Never mind, your script is on my toolbar fixing these .todo files from the Task bundle for TextMate.
Used a lot for writing down brief and minutes associated with a project, I’m glad to finally see a proper icon.
And I won’t tell you how great the Indian Ocean was today