Open Tweet in TweetBot 1.0.1

I updated my Open Tweet in Tweetbot action for LaunchBar. You can download it from GitHub.

The previous version didn’t work properly if you triggered it and TweetBot for Mac wasn’t already running. Now that I’m using Marco Arment’s Quitter and TweetBot is being killed all the time, I was running into this bug a lot. The new update to the action fixes it.

Nerdy Details

Making this fix required doing a check to see if TweetBot was already running and, if not, to launch the app. I wrote the original script in JavaScript. As far as I can tell, there isn’t a way to use JavaScript to see if an app is running or not. But you can do that with AppleScript. And you can call out to an AppleScript from JavaScript. Here is the AppleScript that I’m using:

if application "Tweetbot" is not running then
    tell application "Tweetbot" to launch
    return false
else
    return true
end if

And here’s a line in the action’s main script that calls out to it:

var tweetbotIsOpen = LaunchBar.executeAppleScriptFile("open-tweetbot.scpt")

So the JavaScript calls out to the AppleScript which will launch TweetBot if it’s not already running. That AppleScript will also tell the caller if TweetBot was already running or not. In this case, I store the result of that call in the tweetIsOpen var. If you look at the full code, you’ll see that I’m not actually doing anything with the tweetIsOpen var. The reason for this is that I thought I might have to wait a second after opening TweetBot before sending it a URL to open. Turns out that isn’t necessary. 👍