Get current focus mode via script

THANK YOU! This is awesome, and just what I was hoping was built-in to macOS.

Edited to Add

For those new to jxa, you can save this in Script Editor, just be sure to change the language to “JavaScript” at the top of the window. It can then be saved as a .scpt file.

If you want to use it with osascript without making a .scpt file, then you have to use the -l (That’s a lowercase -L) flag and specify the language, as osascript assumes plain-text is AppleScript. For example, I put the code into a plain-text file named whichfocus.jxa and ran it like this:

osascript -l JavaScript ./whichfocus.jxa

and it worked great.

Andrew - you might consider posting this as a Github gist so others can discover it.

4 Likes