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.
.
Bookmarks