Have you ever thought to yourself ...

Gee, I wish I could focus more on my work and not get distracted by all these Slack and e-mail notifications

and done something about it? By any chance did you install heyfocus?

Because if you did, there's a good chance that just like Brad, you might have experienced some peculiar happenings to do with your keyboard.


Gather round and I'll tell you a story, a story of keyboards and gremlins, a story that starts many moons ago when young Brad bought himself a brand new CODE keyboard, elevating his status from lowly database guy to peerless Database Engineer - among other things - in one simple purchase.

But the rise to power was not an easy one, you see, the keyboard was damaged in transit from over the ocean! It required repair. However Brad lacked the tools and ability to fix his keyboard, so he sought the aid of his newly acquired and handsome young friend, Jason, who fixed the problem without having to search Google for the answer.

Once the keyboard was fixed, work could begin again with renewed vigour.

But it did not last long, like a peaceful summers night in the suburbs only to be interrupted with a child's caterwauling there was a constant loss of focus.

Thus, Brad went on a quest to find a shield that repelled distractions. It was a long and perilous quest, filled with many dead ends, tricks, traps and unhelpful reddit threads.

Eventually he found solace in a field near the town of heyfocus. The towns people greeted him as one of their own, guided him to their temple and showed him the way to remove all distraction from his mind.

In the things he learned was a scroll of magic, and on the scroll were symbols which when copied and written into the panel of "scripting and focusing" perform the spell known as "Do not disturb".

if [[ $(plutil -convert xml1 -o - ~/Library/Preferences/ByHost/com.apple.notificationcenterui.*.plist | grep false) ]]; then
    osascript <<EOD
      tell application "System Events" to tell process "SystemUIServer"
        key down option
        click menu bar item 1 of menu bar 2
        key up option
      end tell
EOD
fi

Brad performed this spell hourly and was not disturbed for months on end, but like most stories there is one last cruel twist of fate to come.

You see, around 4 months later there was an update to the macOS platform known as the Sierra update. That fateful update broke the spells binding, and caused the mighty CODE keyboard to malfunction in strange ways.

Once Brad tried to focus and begin typing, strange things would happen. Keys would no longer work, often leaving him locked out of his computer. Menus would appear randomly as if some unknown hand was holding down the key.

These malfunctions bamboozled his co-workers, leaving them perplexed and unable to explain the situation.

But one early spring morning, Brad noticed that it was his spell causing all of this confusion and upon further research found the answer to be very simple. One that only required a single digit changed. One that should not have been required but was.

Apple had changed their menu bar indexing.

El Capitan

click menu bar item 1 of menu bar 2

Sierra

click menu bar item 1 of menu bar 1

This brings our story to a close but it does not perhaps, leave things very clear for our readers so I will attempt to explain a little more.

In the script Brad was running we need to look at these 3 lines;

        key down option
        click menu bar item 1 of menu bar 2
        key up option      

The script starts out by holding down the option key.

Then clicks menu bar item 1 of menu bar 2. In simple terms this is normally the do not disturb toggle.

But the recent Sierra update changed the indexing of this button. Which in turn causes the script to break while still holding down the option button as it never triggered the line to release it.

There may be more adventures of Brad the Peerless Database Engineer, but for now he works on in silence, using a keyboard that works, being disturbed no more.