Snow Leopard: mass change all icons for a given file type?

Hippo Man

Hippo Man
I have recently changed all my movie files on my Snow Leopard system to be launchable by QuickTime Player 7 instead of QuickTime Player X [see note below]. For various historical reasons, these movie files have a variety of icons associated with them. I'd like to run some sort of utility which does a mass change of the icons of all my movies to the same, one, single icon ... and I'd like to do this in one fell swoop, instead of having to go through an icon change procedure movie by movie by movie by movie by movie by movie by movie by movie ...

After changing all my movies to be launchable by QT 7, I have restarted Finder and restarted my machine, but the old icons remain on all of the movies.

Is there any way that I can perform this mass icon change under Snow Leopard, or am I out of luck?

Thanks in advance.

Note: the following post explains how I changed all my movies to be launchable under QT 7: http://macosx.com/forums/1485770-post7.html
.​
 
I thought of a possibility: is there a way to change a file's associated icon via a command-line procedure (i.e., in a Terminal session)? If so, I could do this:

Code:
find ~ -name '*.mov' | while read item
do
  [I][mysterious command][/I] "${item}"
done

... where [mysterious command] is the command which can change the icon.

Then, I can repeat this for *.avi, *.mp4, etc.

Any ideas as to what that mysterious command could be?

Thanks again.
.​
 
OK. Well, I came up with a way to do it.

First of all, I created a directory called bin under my HOME. Then, in that directory, I put the following shell script into a file called changeIcon:
Code:
#!/bin/sh                                                                                           

prog="`/usr/bin/basename $0`"

[ $# -lt 2 ] && {
  echo "usage: ${prog} \"filesystem-item-with-icon\" \"filesystem-item-to-change\" ..."
  exit 1
}

icon="${1}"
shift

cmd="                                                                                               set newIcon to (POSIX file \"${icon}\") as alias                                                    
tell application \"Finder\"                                                                         
     activate                                                                                       
     set infoWindow to open information window of newIcon                                           
     set infoWindowName to name of infoWindow                                                       
end tell                                                                                            
                                                                                                    
tell application \"System Events\"                                                                  
     tell application process \"Finder\"                                                            
          tell window infoWindowName                                                                
               keystroke tab                                                                        
               keystroke \"c\" using command down                                                   
          end tell                                                                                  
     end tell                                                                                       
end tell                                                                                            
"

done=

for item
do
  [ -r "${item}" -a -w "${item}" ] || continue

  done=1

  cmd="${cmd}                                                                                       
delay 0.25                                                                                          
                                                                                                    
set theItem to (POSIX file \"${item}\") as alias                                                    
tell application \"Finder\"                                                                         
     close infoWindow                                                                               
     set infoWindow to open information window of theItem                                           
     set infoWindowName to name of infoWindow                                                       
end tell                                                                                            
                                                                                                    
delay 0.50                                                                                          
                                                                                                    
tell application \"System Events\"                                                                  
     tell application process \"Finder\"                                                            
          tell window infoWindowName                                                                
               keystroke tab                                                                        
               keystroke \"v\" using command down                                                   
          end tell                                                                                  
     end tell                                                                                       
end tell                                                                                            
"
done

[ -z "${done:-}" ] && exit 0

cmd="${cmd}                                                                                         
tell application \"Finder\"                                                                         
     close infoWindow                                                                               
end tell                                                                                            
"

/usr/bin/osascript -e "${cmd}" 1>/dev/null 2>&1

exit 0

Then, to make changeIcon executable, I issued this command in Terminal:
Code:
chmod +x ~/bin/changeIcon

Then, to run it, I did this, also in Terminal:
Code:
find ~ -name '*.mov' -print0 | xargs -0 ~/bin/changeIcon '/path/to/file/with/desired/icon'

This recurses down through every directory (folder) under my HOME directory and changes the icon associated with every *.mov file.

The tilde (~) to the right of the word find gets replaced with the full pathname of the HOME directory. If you want to recurse through a different directory tree, then use the full POSIX path name to the top level of that directory tree instead of this first tilde.

The wildcard pattern after the -name argument has to be quoted, and all files whose names match it will have their icons altered. In this case, it's '*.mov'.

The /path/to/file/with/desired/icon should probably also be quoted, and it should be the full POSIX pathname of a file which already has the desired icon associated with it. This script will take its icon and associate it with every file that matches the pattern after -name under the directory tree that is named in the first argument of the find command.

There are other ways to use the changeIcon script, including without the find command. If you want to know more, post a question here or send me a private message, and I'll explain it.
.​
 
Neat script. I'm trying to use it to change the icons on all of my PDF files to the bright red Adobe Reader icon (because it's easier to see, not because of ANY love (for which there is none) for the application or the company).

The good news is that I can get this script to work on a local drive, and I can get it to work on a remote drive, so long as the files to be changed are located in or under the "/bin" folder/directory.

But even though it appears to run, this script won't actually change the file icons of any PDF files located outside of whatever "/bin" folder I've specified as containing the script file, even though I'm using full paths throughout the "find" command, and running the CHMOD command, as described in the post.

What am I doing wrong?
 
Back
Top