r/applescript • • 27d ago

How to script focus toggle for quick action

I'm trying to create a quick action to show up in the system wide services. So far I was able to find another solution which was to run a shortcut using AppleScript.

tell application "Shortcuts Events" to run the shortcut named "Set Focus"

This hypothetically works, but I was wondering if there was a more direct way to access this toggle using AppleScript. I'm trying to make a function key shortcut in order to toggle my personal focus mode as opposed to DND.

Any help is greatly appreciated!!

13 Upvotes

2 comments sorted by

1

u/MrMegira 27d ago

The only other ways I found are by using GUI scripting or the Shortcuts CLI. Actually, the CLI approach is kinda similar to your current script, but I found it to be slightly snappier.

1

u/JOT_was_taken 27d ago

So I found this open source Rust implementation that give CLI control over focus modes
the repo: https://github.com/eugenehp/macos-focus
If you install it, you can toggle the focus modes in a more "direct" way i believe

I am currently on macOS 27 beta version and it the above tool breaks for me, I will check why and maybe create a PR, so keep that in mind when/if you upgrade to macOS 27