Skip to content

Small app that checks focus status under macOS 12

Notifications You must be signed in to change notification settings

bartreardon/infocus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

infocus

swift-version macos-version xcode-version

install

What

Small app for Mac Admins that checks focus status under macOS 11 and 12 and can be used to add Do Not Disturb support to management scripts.

Infocus runs from the command line. If the user has a Focus mode set, infocus exits with code 1, otherwise exits with code 0

For a pre-built preview, check the Releases page.

Why

Because you're a nice #MacAdmin that doesn't want to disturb your users with some popup or other event that ordinarily wouldn't adhere to macOS Notification framework.

How

Through the Magic of Swift! on macOS 11 it reads a local plist to get DND data. Under macOS 12 it uses the communications notifications entitlements but because of app sandbox rules that come with adding the entitlements, required for macOS 12, there is a seperate infocuscli binary included in the app bundle for use on macOS 11. Within the sandbox the app can't read the local plist. Fun.

Demo

The following script will run the correct version for the OS, check focus state and exit if focus/DND is enabled

#!/bin/zsh

infocusapppath="/Applications/Utilities/infocus.app"

autoload is-at-least
if is-at-least 12.0 $(sw_vers -productVersion); then
    infocus="${infocusapppath}/Contents/MacOS/infocus"
else
    infocus="${infocusapppath}/Contents/Resources/infocuscli"
fi

# Running Infocus - if DND is enabled (i.e. exit code is 1), then exit
if [[ -e ${infocus} ]]; then
  ${infocus} || exit 0
else
  echo "Infocus is not installed - Do Not Disturb preferences will not be considered" 
fi

# ... continuing with the rest of the script if focus/DND is not enabled.
# ...

Compiling

Requires Xcode 13.1 or newer, which includes the correct frameworks for macOS 12.

After building, run codesign --force --deep --sign - infocus.app on the app bundle to fix the signature for distribution.

About

Small app that checks focus status under macOS 12

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages