Using Keyboard Maestro to enforce TweetMarker usage with Twitterific

A common request amongst Twitter users is for timeline syncing across devices. Personally, I use Twitter on my iPhone, iPad, MacBook Air and iMac. Checking on one, then later checking on another can be a huge pain, as the locations within the timelines are separate on all devices.

Tweet Marker

Recently Manton Reece released a new service named Tweet Marker. This is an API that authors of Twitter clients can take advantage, which will sync your location within the timeline up to a server, allowing other clients using the API to pull that location when you launch them. So if I check Twitter on my iPhone with Tweetbot, then an hour later load up Twitterific on my MacBook Air, Twitterific will automatically jump to wherever I was on the timeline when I exited TweetBot.

It's a terrific service, and works very well. As a long time user of Twitter, I'm happy we've finally got something like this.

One negative aspect of it (at least according to my understanding) is that the API is a little more focused on iOS devices. Namely, devices where you "quit" the Twitter app all the time, i.e. hitting the Home button. iOS Twitter clients taking advantage of Tweet Marker will explicitly sync their timeline position whenever you quit the app.

On the Mac, this causes a bit of a problem. It's more common to just leave your Mac apps running, rather than quitting them whenever you want to switch focus to something else. This results in Twitterific on the Mac rarely syncing its current position up to the Tweet Marker servers. If I could remember to quit Twitterific whenever I walked away from my Macs this wouldn't be an issue, but that's not something I'm going to remember.

What I needed was a way to automatically quit Twitterific after a set amount of time. They've got something like that coming in a future version, but even that functionality won't work for me. Namely, their support will only sync the timeline whenever the computer goes to sleep. My iMac *never* goes to sleep. I let the screen shut off, but my iMac runs a few server processes, so I can't have it sleeping.

The eventual solution I came up with was a combination of SleepWatcher and Keyboard Maestro.


SleepWatcher is a nifty little tool that runs in the background and can execute scripts of your choosing based on time-conditions. You can run scripts when the computer sleeps, when the monitor sleeps, after a settable idle time, when the computer wakes up, etc. What I want is to automatically shutdown Twitterific after my computer has been idle for 5 minutes.

To use SleepWatcher, you install it (follow the instructions that come with it) and create a .plist entry in your ~/Library/LaunchAgents directory. SleepWatcher comes with some example .plist files, but I've uploaded mine here. To tell your system to use this file, simply place the file into ~/Library/LaunchAgents/ and run the following command:

launchctl load ~/Library/LaunchAgents/ca.parlar.sleepwatcher.plist

(Of course you'll rename ca.parlar.sleepwatcher.plist to something related to you)

The two key aspects of this file are the --timeout=3000 entry, which tells it to use an idle time of 5 minutes, and -i ~/bin/quit_applications which tells it to run the script quit_applications after the machine has been idle (-i) for the time specified by --timeout.

quit_applications is a script that, for me, looks like:

osascript -e 'tell application "Keyboard Maestro Engine" to do script "20ADAD78-FAB4-4709-80B6-CF497FC6FF0E"'

Where does that come from? Keyboard Maestro.

Keyboard Maestro

Keyboard Maestro is an application that can seemingly do anything. It lets you build very powerful macros that can be activated by keyboard shortcuts, menu drop-downs, scripts, and lots of other events.

The scripts option lets an Apple/Perl/Python/Ruby/Shell script activate a Keyboard Maestro macro. My macro for this setup is:

I've got the macro doing a few things more than just shutting down Twitterific after an idle time, and those can easily be changed to reflect whatever you might want to happen on your own system.

Using this combination, I've now got Tweet Marker working quite nicely across all my systems. Twitterific gets shut down on my Macs after a period of time. As long as I don't run a Twitter client on my iPhone/iPad in the 5 minutes before the iMac has an idle event, then everything is great.

Thanks again to Manton for the awesome Tweet Marker service, and the good folks behind Twitterific for Mac and iPad, and TweetBot (my current iPhone Twitter client). Thanks as well to Bernhard Baehr for SleepWatcher and Stairways Software for Keyboard Maestro.