DEV Community

Cover image for Matt's Tidbits #89 - Automating focus time
Matthew Groves
Matthew Groves

Posted on • Originally published at Medium

Matt's Tidbits #89 - Automating focus time

Last week, I wrote about Android Studio's "Patch" feature. This time, I want to share what I've done to help myself have better focus time.

I've finally admitted that I easily get distracted. Slack, email, etc. all provide a nearly constant barrage of inputs, and sometimes it's impossible to go even 5 minutes without a new message coming in.

The most surefire way to help myself focus is to quit all of my communication apps, but that isn't always the best idea, as I don't want to just cut myself completely off from the rest of my team.

There are lots of things you can do, but one of the most effective ones I have found is setting a status in Slack and marking myself as "Away". (This lets other people know I'm trying to focus, and requires them to push an extra button if they want to notify me of a message - so they can still reach me, but only if they really need to). However, I have multiple Slack workspaces, and I personally find it a little time consuming to perform all of those steps for each workspace. I place a lot of value on automating repetitive tasks, so I got to work on writing some scripts to do this automatically.

I use a Mac for my work, so the first approach that came to mind was Automator or AppleScript. Unfortunately, Slack doesn't have built-in support for Automator actions, but I did find a GitHub project with a library of AppleScript commands!

GitHub logo samknight / slack_applescript

AppleScript bundle for Slack methods

Slack Applescript Automations

This bundle allows you to automate actions in Slack

Please consider buying me a coffee if this has made your work easier

ko-fi

Important note

Please use v2 and above for Slack ~4.10 and above. v2 supports the new shortcuts menu in Slack. Please review the commands below to see the scripts that could not be made backwards compatible.

To install


Clone this repository and unzip the Slack.zip archive into your ~/Library/Script Libraries (If this doesn't work try putting it in ~/Library/Scripting Libraries)

The scripts are now accessible globally. Documentation can be found in the script Library.

Contributing


The src file contains the source code - please make changes to this code and then export and zip the bundle.

Applescript tutorial


If you need a beginners guide to applescript please look at my blog post

To use


all of the commands below can be accessed by nesting…

Using this, I was able to whip up a pair of scripts - one that sets a status and marks myself as away for all of my Slack workspaces, and another that clears my status and sets me as active!

You can find the scripts here:

GitHub logo mpeng3 / slack_automation_scripts

AppleScripts to automate setting a status/away and clearing it.

slack_automation_scripts

AppleScripts to automate setting a status/away and clearing it.

These scripts require this AppleScript Slack library to run: https://github.com/samknight/slack_applescript

To use:

  1. Download the "Focus.applescript" and "Resume.applescript" files to your computer.
  2. Open each app using the "Script Editor" application on your Mac.
  3. Edit the status message/icon you'd like to use for when you're having "focus time".
  4. Add/Remove the main blocks of code to reflect which Slack workspaces you'd like to update, as well as the keystroke number for that workspace (in Slack, pressing Command+1 navigates to your first workspace, Command+2 to the second, etc.)
  5. Export your changes as an "Application", so you can run the script on its own.
  6. Add a fun icon to your applications, if desired! You can do this by running File->Get Info from the Finder, clicking on the icon in the upper-left corner of that window, and then pasting in an image of your choice.
  7. Try…

To use, follow the instructions in the README for the project.

This is just one example of some time-saving automation you can write yourself! The possibilities are nearly endless! Do you have suggestions for how I could improve these scripts? Leave a note in the comments below or feel free to submit a pull request yourself! And, please follow me on Medium if you're interested in being notified of future tidbits.

This tidbit was discovered on January 25, 2021.

Top comments (0)