Scripting Focus with macOS URL Handlers

Learn how to script Focus with customer URL handlers, allowing you to start Focus from anywhere!

Focus supports OS X URL handlers, which means you can turn it on and off from the browser, operating system and 3rd party apps.

In the browser

For example, try clicking the links below:

Focus or Unfocus

If you have Focus installed it will turn the app on or off (you may have to click approve if a dialog comes up).

Here's the HTML to perform this:

<a href="focus://focus">Focus</a> or <a href="focus://unfocus">Unfocus</a>

In the terminal

In the terminal, you could turn Focus on by typing

open focus://focus

Or turn Focus off

open focus://unfocus

You can also pass in a duration

open focus://focus?minutes=30&seconds=30

Or just toggle to a different state

open focus://toggle

Calendar

Focus has scheduling features, but with scripting it can also be turned on & off from your Calendar by using Automator & Calendar alarms. Here's how:

You can skip to step 5 if you want to download the existing Focus Automator workflows. Otherwise:

  1. Open Automator and create a new Calendar Alarm workflow

    Create Focus workflows in Automator

  2. Add a new Run Shell Script action

  3. Add code to action that invokes Focus

    /usr/bin/open focus://focus

    Add run scripts that invoke Focus for automator workflow

  4. Export the action. Also create an unfocus action if required.

  5. Create a new event in Calendar with an alert type of Custom... (only works with regular Calendar events, not Google)

  6. Select Open file and Other... for the first and second options

  7. Select the exported Automator workflow from step 4 that triggers Focus

  8. Set the last option to At time of event

Create custom alert on calendar to invoke Focus scripts

Now, when your Calendar alarm goes off, Focus will run the Automator script which will turn Focus on or off.

3rd party apps

Focus is also easy to integrate with other 3rd party apps like Alfred.

Focus integrates well with 3rd party apps like Alfred

Download the Alfred workflow and quickly enable or disable Focus with an alfred command.

Have other awesome Focus integrations? Let us know at @heyfocusapp or [email protected]

Having a hard time staying on task because of distractions? Focus is an app for your Mac computer that helps you stay on track. It blocks things that can distract you so you can get your work done. Try Focus and see how much better you can do!
Download Focus
← Back to blog
Focus Productivity on December 23, 2014