Hello, great site! Thanks for having me aboard. I got my hands on a very cool AppleScript from Apple Discussions that copies icons from the information window of the chosen file or folder and transfers these icons to a folder or file of your choosing. However, it has one annoying limitation. If the file (Source object) has a “generic” icon, the generic icon will be undesirably copied to the Target object. I have a shell script that should solve this problem (“/usr/bin/sips -i "$@"”) and I’d like to know where I can add it to this AppleScript. I made a couple of modifications to this script and it didn’t have a name so I took the liberty of naming it “Iconizer”.
Iconizer:
on run {}
set theSourceObject to my DetermineLocationOfObject("source")
set theTargetObject to my DetermineLocationOfObject("target")
my ApplyCustomIcon(theSourceObject, theTargetObject)
end run
to DetermineLocationOfObject(ObjectType)
display dialog "Is the " & ObjectType & " object going to be a file or a folder?" buttons {"File", "Folder"} default button 2
if button returned of the result is equal to "File" then
set theObject to choose file with prompt "Please locate the " & ObjectType & " file."
else
set theObject to choose folder with prompt "Please locate the " & ObjectType & " folder."
end if
return theObject
end DetermineLocationOfObject
to ApplyCustomIcon(SourceObject, TargetObject)
my HandleInfoWindow("source", SourceObject)
my HandleInfoWindow("target", TargetObject)
end ApplyCustomIcon
to HandleInfoWindow(ObjectType, theObject)
tell application "Finder"
activate
set InfoWindow to name of (open information window of item theObject)
end tell
tell application "System Events"
tell application process "Finder"
tell window InfoWindow
keystroke tab
if ObjectType is equal to "source" then
keystroke "c" using command down
else
keystroke "v" using command down
end if
end tell
end tell
end tell
tell application "Finder"
close window InfoWindow
if ObjectType is equal to "target" then display dialog "Icon transferred." buttons {"OK"} default button 1 giving up after 5
end tell
end HandleInfoWindow
Model: eMac G4 1.25 GHz
AppleScript: 2.1.1 (81)
Browser: Safari 3.0.4
Operating System: Mac OS X (10.4)