I’ll give this a shot.
on run
open {choose file}
end run
The “on run . . . end run” code gets executed when the script starts (unless it is started by dragging a file on to it, but more about that later). This article [url]http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScript.e4.html/[url] gives some specifics. I’m not too familiar with php, so I’m not sure what to compare it to, but in C it would be like the “main” function.
“choose file” is an Applescript command which will open up a file selection dialog so that the user can choose the files to modify. This list of files is passed to the “open” handler.
This run handler is here so that the user can click on the icon for the script to use it, instead of dragging the files onto the droplet.
The “open” handler is called by the “run” handler as described above if the user clicks on the icon. However, if the user drags files onto the droplet, then the “open” handler is called.
on open the_files
the_files contains a list of the files to be used. It is a parameter of the “open” handler. It is set either by the “run” handler or by the system when files are dragged onto the droplet.
if name of the_info ends with ".mov" or file type of the_info = "MooV" then my process_this_file(this_file)
One of the blessings/curses of the Mac is that a file’s extension is not the only way to specify the file type. I could have a Quicktime movie file that ended in “.txt”. Quicktime movie files have a type of “MooV”. This seems silly, but say it out loud. “Moo”. “V”. “Moo” “V”. “MooV”. (Remember the two-headed monster on Seasame Street?) This code is looking at the file and making sure that it is of the right type. This avoids the problems that you would have if you tried to remove the sound track from a Word document.
on process_this_file(this_file)
tell application "QuickTime Player"
open this_file
delete track "Sound Track" of movie 1
close movie 1 saving yes
end tell
end process_this_file
This part had confused me when I started dealing with AppleScript. When you are inside of a “tell” block, you are talking to the application. Think of it as having a conversation. First, we tell QuickTime Player to “open this_file”. QuickTime Player does that, and it stores a representation of that file in a list of movies that are open. You can refer to this movie as “movie 1”. You don’t have to tell QuickTime Player to do this, it does it automatically. So the second line of the “tell” block is telling QuickTime Player, “Delete the track called ‘Sound Track’ from the first movie in your list of movies that are open.” The third line tells it to save that movie and close it.
One of the hardest things about AppleScript if you come from a language like Pascal or C or PHP is that quite a few things happen without you directly asking for them to happen. It can be kind of scary, especially when you are trying to figure out exactly what it is that the application has done for you. Don’t try to fight it. I almost gave up on AppleScript after hours of trying to access a movie in QuickTime
Hopefully this has helped. I you are looking for a good place to start with AppleScript, try “AppleScript for Absolute Starters” here http://www.applescriptsourcebook.com/tips/AS4AS.html.