Extending MacID for OS X

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:

Exporting an AppleScript script

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.

6 thoughts on “Extending MacID for OS X”

  1. This is a very cool feature, I’ve added scripts to automatically turn off my office Hue lights when I leave the room (MacID proximity locks my Mac) and to fade up when I return (MacID proximity knocks my Mac). Next I’m hoping to write a script that reports my Mac lock status over http and relays that information to HomeKit for further automation.

  2. Great but could be even better. I hate iTunes (but will not uninstall it) and use i.e. Radium for playback. The play/pause buttons in MacID don’t work with Radium. Locally, I use Karabiner to remap the media keys to F7-F9 and that works perfectly with Radium. But MacID still wants to launch iTunes. If I could have scripts for those buttons too I could easily control anything from my iPhone.

    Please add this to your otherwise fantastic product!

    1. May be you can do it like this:
      tell application “QQMusic” to activate
      tell application “System Events” to tell process “QQMusic” to tell menu bar item 4 of menu bar 1 to click menu item 1 of menu 1

      1.You need to change the 「application」 to the app you want.

      2.Then you need to modify the second part of the code according to where the pause/play command is on the menu bar.

Leave a Reply

Your email address will not be published. Required fields are marked *