Jump to content

Workflow hotkey toggle

Recommended Posts

Is there a way to setup a toggle with a hotkey to flip between these two Apple Shortcut actions? I'm struggling to create the logic flow for this.



1. Press the hotkey, and the app is muted.

2. Press the hotkey again, and the app is unmuted.



Link to comment

I'm sure someone will have a better idea but (assuming the mute command itself in the shortcut is not a toggle) the only simple way I can think of doing it at the moment is to have a text file in the workflow folder which records the last action (i.e., mute or unmute). If you then read that file when running the shortcut you can:

  • then run the opposite shorcut; and
  • write again to the file recording the latest operation.


Link to comment

The other option is to have an action which determines the current state (muted or unmuted) at call time and outputs that information. But it’s unclear if that’s feasible, as screenshots don’t provide any information about your specific case. We have no idea what the Arg and Vars is for or what those shortcuts do internally.

Link to comment

Unfortunately, getting the current state of the application's mute status isn't available. Only setting explicit mute values "Mute" or "Unmute" are available. That's why I have two shortcuts, one for mute and one for unmute. It's not my ideal either. If I could set this up in shortcuts, I would do that and then just invoke the one shortcut with a hotkey.

Is writing and reading a text file the only way to make a toggle in Alfred? I'm surprised.

FWIW, I'm working with SoundSource shortcuts. Setting mute or unmute for an application is possible, but getting mute status for an application is not.

Link to comment

You are welcome!


1 hour ago, BigLaser said:

Why is this an apple script contained in a zsh script instead of just an apple script?


This is just to more conveniently access the environment variable '${alfred_workflow_bundleid}' and the argument.

Link to comment

Purely for reference, here’s the AppleScript version:


on run argv
  set newState to item 1 of argv
  set workflowBID to system attribute "alfred_workflow_bundleid"
  tell application id "com.runningwithcrayons.Alfred"
    set configuration "state" to value newState in workflow workflowBID
    reload workflow workflowBID
  end tell
end run


Link to comment
13 hours ago, zeitlings said:

You are welcome!



This is just to more conveniently access the environment variable '${alfred_workflow_bundleid}' and the argument.

Interesting, thanks for the clarification.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...