![]() – A string beginning with ASCII: which signifies that the rest of the string is interpreted as a special form of ASCII diagram, which will be rendered to an image and used as the icon. ImageData … can be one of the following … Hammerspoon of course provides a setIcon method on menubar to help us provide an image icon, so we’ll just grab a Slack icon from the web and-whoa, what’s this? But wait, we can make this even better: The best menu bar apps have nice icons and ours should, too. Now we need a timer to periodically refresh the menu bar. With some simple scripting, we’ve created a highly personalized, native-looking integration into the menu bar. But what is menu? That must be complicated. ![]() ![]() Let’s write that: local function callback (status, body ) - errors get a status of -1 if status 0 then ![]() You’ll notice we’re passing a callback to fetchData, which will be responsible for doing something with the response JSON. asyncGet (fetchUrl, nil, callback ) end First we create a function to fetch the necessary counts from Slack’s API: local slackToken = 'xoxp-xxxx' local fetchUrl = ''. I’d previously implemented this using a shell script, so I had a pretty good starting point. Building a Slack notifier for the menu bar When I click on it, it should open Slack. The task is beginning to take shape: I want a simple indicator in my menu bar that shows the number of unread mentions and DMs I have. Of course, Slack’s API is rich enough that you can probably assemble your own “interruption metric” based on how you and your team use Slack. An indicator that shows a count of my unread mentions and DMs strikes the right balance, at least for me, between being able to focus and knowing I’m able to be interrupted if there’s something important I need to attend to. Still, it’s important for me to have some sense of when I might be blocking the work of my colleagues. Like many of us, I’ve realized that the only way to truly focus at work is to close Slack. This post isn’t about Slack, but if you use Slack at work you probably have a love/hate relationship with it: it’s the fun and immediacy of a chat room-shoved down your throat all day, every day. That brings us to why I wanted to create a custom menu bar app. Don’t let that deter you, though-dive into the docs and you’ll quickly be inspired to create your first “spoon.” Plus, learning a new language is always fun and Lua is a quick study. You won’t find much example code and screenshots are basically non-existent. The first thing you might notice when checking out Hammerspoon is that its documentation and GitHub page, while thorough, are pretty buttoned-up. In reality it is immensely powerful and feels wonderfully native, with a rich API that leverages the power of the Lua scripting language. I had run across Hammerspoon more than a few times while stalking other people’s dotfiles, but I had pigeonholed it as a simple automation tool for launching applications and tiling windows. I just wanted to create a simple Slack integration into the menu bar (more on that later), but it seemed my only recourse was to build an entire app from scratch. I kept searching, but everything I found was either hopelessly broken or entirely too opinionated. If you search the web for “custom menu bar app” or something like it, you’ll probably be pointed towards BitBar-which comes tantalizingly close to delivering on its promise to “put the output from any script or program in your Mac OS X Menu Bar.” Unfortunately, it’s basically abandonware and has two big issues that render it unusable for me: (1) the menu bars you create are maddeningly misaligned by one pixel and (2) it’s incompatible with menu bar hiders like Bartender and Dozer. Thankfully, you can now reorder menu bar apps (command + drag) and you can often remove the ones you don’t want. Yet somehow it’s both underutilized (lots of empty space, especially on big monitors) and overutilized (needlessly cluttered by tasteless “updaters” and other daemons). It’s the one interface element that remains constant as you navigate across applications. Still, the inability to easily customize the menu bar gnaws at me. I’m a system tweaker by nature but, for the most part, I’m at peace with the limitations of macOS because I know that they exist to protect us from our more careless instincts.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |