GUI scripting: it's not as evil as you think, but it involves a lot of tell blocks (see the very first post here for info on Tell blocks)
First off, head to System Preferences, click Universal Access and allow access for assistive devices. Without this, you're sunk. Come back after you've clicked it.
Got it clicked? Great, now you're ready to make an AppleScript. Launch Script Editor and ger ready to tell it a whole lot of stuff. Let's pretend we're going to work in the Finder, so start off with:
Tell Application "Finder"
activate
end tell
All right, now let's look at that menu bar (that's the thing at the top of the screen that has the application name on it). We're going to make the Finder use the select all command. This is done by manipulating an application buried deep inside of OS X called System Events (and you don't need it to activate either, which is weird). So our starter code is:
tell application "System Events"
tell process "Finder"
Note the Finder becomes a PROCESS now instead of an application. This is normal. Now we have to tell what we're aiming for, which is the menu bar:
tell application "System Events"
tell process "Finder"
tell menu bar 1
But wait, there are more tell blocks, because you have to tell the GUI where to go in that menu bar (in this case, "Edit"):
tell application "System Events"
tell process "Finder"
tell menu bar 1
tell menu bar item "Edit"
tell menu "Edit"
Note we have to get the Edit menu mentioned twice, once as a menu bar item and once as a menu. For every item that reveals a menu, it has to be mentioned twice or the script will fail (see my
Safari Debug script if you'd like an example of mutiple menus). For now we're dealing with one menu and we've hit gold--we've found Select All! So you have to tell the GUI to click it:
tell application "System Events"
tell process "Finder"
tell menu bar 1
tell menu bar item "Edit"
tell menu "Edit"
click menu item "Select All"
All right! Now we have FIVE tell blocks that need to be told their work is done, so now we insert five "End Tell" statements:
tell application "System Events"
tell process "Finder"
tell menu bar 1
tell menu bar item "Edit"
tell menu "Edit"
click menu item "Select All"
end tell
end tell
end tell
end tell
end tell
And you've just bent the Mac OS GUI to your will.