Fun With AppleScript

Lately, I’ve been really getting into AppleScript. I’ve found it to be easy to work with and very convenient for automating repetitive tasks in some of my daily communications/tasks. It’s also a nice and relatively productive way to take a break from work, game dev, and anything related to 3D.

For those of you who don’t know about AppleScript, here’s a blurb from Apple’s Getting Started With AppleScript page:

AppleScript is a scripting language that provides convenient control of applications and of many parts of the Mac OS. AppleScript uses an English-like syntax that is accessible to scripters with little programming experience. Scripts can combine operations from applications and from the Mac OS, to automate simple tasks or complex workflows.

I’m presently using custom AppleScripts in Mail, MarsEdit, BBEdit, and Conversation. Most of the scripts are written by other people, but I do hope to write more of my own as I learn more about AppleScript.

The majority of my custom scripts are presently used in Conversation. I tend to change my nickname in IRC channels frequently, so, rather than type out long-winded commands to change the name and authorize the ones I have registered, I like to use scripts to automate them. Conversation allows me to use AppleScripts as /commands, so I can just type the name of the script to execute it.

Here’s a quickie one that changes my name to “danny” and then authorizes the nickname if the name of the current server contains “maxgaming” (maxgaming.net’s IRC servers have registered nicknames).

applescript.jpg

Every time I type “/danny” in Conversation, the script does its magic, and I’ve saved myself a bunch of typing. The script only took me about 20 minutes to put together, and most of that time was figuring out the correct syntax for Conversation’s script library. I’m still not very fluent in AppleScript, so this probably took far longer than it should have.

Learning how to create AppleScripts is actually kind of fun. While the English-like syntax can be tedious sometimes (nightmares of pre-dotSyntax Lingo in Director come to mind immediately), it is very easy to work with and makes reading other people’s scripts go much faster. Apple’s free Script Editor application (bundled with OS X) makes writing scripts go very fast with syntax coloring, auto-completion, and auto-formatting. Best of all, you can actually use AppleScript to create self-contained applications. I haven’t quite gotten to that point yet, but I hope to be there at some time in the future.

Technorati Tags: | |
Share This:
  • Digg
  • del.icio.us
  • StumbleUpon
  • Technorati
  • Google
  • TwitThis
  • E-mail this story to a friend!