Scripting Focus with OS X URL Handlers
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:
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
Or turn Focus off
You can also pass in a duration
Or just toggle to a different state
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:
Open Automator and create a new Calendar Alarm workflow
Add a new Run Shell Script action
Add code to action that invokes Focus
Export the action. Also create an unfocus action if required.
Create a new event in Calendar with an alert type of Custom… (only works with regular Calendar events, not Google)
Select Open file and Other… for the first and second options
Select the exported Automator workflow from step 4 that triggers Focus
Set the last option to At time of event
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.
Download the Alfred workflow and quickly enable or disable Focus with an alfred command.