Jump to content

Disable other workflow and close an app?

Recommended Posts


I would like to create a workflow that quits a certain app (if it's open), and disables / deactivates one of my Alfred workflows. Is this possible? Can anyone link me to a workflow with similar functionality that I can adapt for my needs? I'm not much of a scripter, but if it's close enough I can probably make it work. As a bonus, it would be great if there were an easy way to re-activate the workflow and re-open the app, but if I had to do that manually that would be fine, too.


What's the use case? Video games, haha. If I forget to quit that app and disable that workflow before playing (which happens more often than I'd like to admit), certain movements cause my hotkeys to fire, usually in the heat of battle, taking me out of the game at the worst possible moment.


Thanks for your help!

Link to comment
  • 1 month later...
On 3/10/2022 at 3:33 AM, Vero said:

@Sticky Your best bet would be to set the workflow hotkeys to be ignored when certain apps are in focus, using the "Related Apps" tab

Hello again. A follow up question on this same theme: Is there a way to ignore a global hotkey when a certain app is OPEN (whether it has focus or not)? Would I need some scripting for that? Or for a workflow to only open an app if it isn't already open?


Use example is the same as above: I use Things for my to-do list/reminders. I have a hotkey set Ctrl+Shift+Space which (when Things is open) opens a "New To-Do" window on top of whatever application currently has focus. But sometimes Things is closed (when I play video games and forget to start it again), and in those cases I would like that same hotkey to launch Things so that I can wait a second and then hit the hotkey a second time and get the expected pop-up window.


So in a workflow, I have that same hotkey set to open Things, so that if it's closed it will open when I hit the hotkey. But, as you would expect, when Things is open, the hotkey is working twice (once by Things and once by Alfred). The end result is not that bad, really: it opens the new To-Do window, and it also opens Things, which brings it to the foreground. This is not a huge deal, and I've been living with it like that for a couple weeks, but it would be nice if I could have Alfred ignore the hotkey when the Things app is open. Is there an easy way to do this?  Or an even smarter, more efficient Alfred way to accomplish the same thing? 😄 Thanks!

Link to comment
7 hours ago, Sticky said:

Is there a way to ignore a global hotkey when a certain app is OPEN (whether it has focus or not)? Would I need some scripting for that?


In a Run Script with Language /usr/bin/osascript (JavaScript), put the following code:


function run() {
  try {
    return Application("Safari").running()
  } catch(error) {
    if (error.errorNumber === -2700) return false


Replace Safari with the name of the app you want to check. Then use a Conditional Utility to check for either true or false and act accordingly. You may need a Transform Utility set to Trim Whitespace between those two.

Link to comment

This works! For anyone else who sees this in the future, I did exactly what he described: Hotkey trigger ->  usr/bin/osascript (JavaScript) -> Transform (Trim Whitespace) -> Conditional (is NOT equal to false), then do nothing. Else -> Launch App.


Thank you so much!

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...