How to make a global keyboard shortcut to toggle your Mac Mastodon app’s visibility
By: Brian Webster |
I was a happy user of both Twitteriffic and Tweetbot on both Mac and iOS for many years, until of course Elon burned everything to the ground and kicked out all the third party Twitter clients.
I’ve moved over to Mastodon now, and while there are several decent Mastodon apps on the Mac, most of them are designed for iOS first and lack one of my favorite features from both Twitteriffic and Tweetbot: a global keyboard shortcut that will bring your timeline window forward to read, then hide it again when you’re done.
Until my favorite feature gets implemented by the apps, in the meantime I’ve come up with a solution using AppleScript to get the same effect. I thought others might find it useful, so here’s how to do it if you want.
1. First you’ll need something to handle the global keyboard shortcut. My tool of choice is FastScripts, but any app that lets you trigger an AppleScript with a global keyboard shortcut will suffice.
2. Open Script Editor, paste in the following script, and save it in ~/Library/Scripts so FastScripts will include it in its script menu. The following script is using the app Ivory, but you can replace the “Ivory” name with whatever Mastodon app you’re using.
tell application “System Events”
if exists process “Ivory” then
**tell** process “Ivory”
if visible then
**set** visible to false
else
**tell** application “Ivory” to activate
**end** if
**end** tell
**end** if
**end** tell**
**
3. Use the FastScripts preferences window to assign your preferred keyboard shortcut to run this script.
Now, whenever you press your shortcut, if your app is not in front then it will be brought to the front. If the app window is already in the front, then the script will hide the app for you. Enjoy!