A lesser-known feature I added to MacID v1.3 was the ability to extend MacID with AppleScript.
You can now get MacID to run AppleScript scripts (exported as text files) when your Mac sleeps, locks, wakes and unlocks. For example, you could pause iTunes when your Mac locks and resume playback when your Mac unlocks.
There are four sub-directories in the MacID directory, which you’ll find in Application Support. To find this, open Finder, click Go at the top of the screen and type or copy/paste in ~/Library/Application Support/MacID. Here you’ll see onLock, onSleep, onUnlock and onWake directories. There are where you will drop AppleScript text files to be executed at the appropriate times.
Now you know where the directories are, lets get AppleScripting!
Here’s a simple script to pause iTunes:
tell app "iTunes" to pause
On your Mac use Spotlight to search for AppleScript Editor and open the app. Create a new file and paste the script above into the editor. Click File and Export…, and then from the window that appears make sure you choose Text as the File Format:
Then save the file and drag it to the onLock directory we found before. Start iTunes playing and then lock your Mac using MacID. Your music should pause shortly after locking your Mac. Neat!
Writing an AppleScript to play iTunes is just as simple:
tell app "iTunes" to play
Follow the same steps as above but this time drag the file into the onUnlock directory. Now lock and unlock your Mac using MacID, your music should now start playing where it left off.
And that’s really it! If you’ve got any useful scripts to share with other MacID users leave them in the comments, and if you’d like to see other events you can execute AppleScripts on (like connecting/disconnecting) let me know.