Floating.Point Posted October 14, 2021 Share Posted October 14, 2021 Does anyone know if there's a way to have Alfred run a single specific script every time the Alfred window closes? So whenever a workflow finishes, or a file action is performed, or even just when Alfred has been cancelled – I want to send a little command, externally. The reason for this is I'm using Karabiner Elements to put my keyboard into a special "Alfred mode" whenever Alfred is invoked. I'm hoping to find a simple way to get out of this mode. At the moment I have these specific rules in Karabiner to try catch any keyboard / mouse event that could close the Alfred window, but it's getting out of hand. It would be much simpler if Alfred (or the system) could execute a script whenever the Alfred window closes. Does anyone have any thoughts? Link to comment
deanishe Posted October 14, 2021 Share Posted October 14, 2021 (edited) 6 hours ago, Floating.Point said: Does anyone have any thoughts? @Mr Pennyworth might have some ideas: he's written a couple of applications that need to know what Alfred's doing. You might be able to use the notification API Andrew added for him, which would be absolutely ideal. The only thing I can think of is an AppleScript that launches Alfred, then waits for it to close: -- Do stuff here to enter "Alfred mode" -- Open Alfred tell application id "com.runningwithcrayons.Alfred" to search "" tell application "System Events" tell application process "Alfred" -- Wait for Alfred window to appear repeat while (count windows) = 0 delay 0.1 end repeat log "Alfred open" -- Wait for Alfred window to disappear repeat while (count windows) > 0 delay 0.1 end repeat -- Exit "Alfred mode" here log "Alfred closed" end tell end tell You could do your setup and teardown in the script or before it runs and after it exits. Edited October 14, 2021 by deanishe Floating.Point 1 Link to comment
Floating.Point Posted October 15, 2021 Author Share Posted October 15, 2021 This is fantastic! I can't thank you enough. I needed to adjust this a bit, to make it suitable for my needs. I needed to trigger a workflow's external trigger (instead of just launching Alfred). So building on what I learned from yourself and Vitor about sending variables to AppleScript using ARGV, I was able to save this AppleScript as an executable, then call it from a shell script, feed variables into the trigger, workflow and argument fields… and I kind of knew what I was doing throughout this whole process. Now I have a lovely reusable little script where I can launch Alfred into a specific workflow, and have my system track whether I am in Alfred mode or not. Thank you so much for your really valuable help! Link to comment
deanishe Posted October 15, 2021 Share Posted October 15, 2021 Glad you got it working, and thanks for the beer money 👍 What's your "Alfred mode"? Link to comment
Floating.Point Posted October 16, 2021 Author Share Posted October 16, 2021 (edited) 21 hours ago, deanishe said: What's your "Alfred mode"? Im using Alfred to display a bunch of context sensitive modal menus. My Alfred mode remaps keypad numbers to include the command modifier, so I can execute Alfred list items with a single keystroke. I also temporarily remap some close-by keys to page down and page up so I can quickly move through any longer Alfred modals Edited October 16, 2021 by Floating.Point deanishe 1 Link to comment
deanishe Posted October 16, 2021 Share Posted October 16, 2021 49 minutes ago, Floating.Point said: My Alfred mode remaps keypad numbers to include the command modifier, so I can execute Alfred list items with a single keystroke. That's a clever idea. You might consider sharing your scripts and Karabiner config on the forum or GitHub (as a gist, perhaps). I'm sure some people will find that really useful. Link to comment
vitor Posted October 17, 2021 Share Posted October 17, 2021 20 hours ago, deanishe said: I'm sure some people will find that really useful. Or even just plain interesting. I’m not a Karabiner user, but from a technical perspective I’d be curious to see this configuration. Link to comment
Floating.Point Posted October 17, 2021 Author Share Posted October 17, 2021 Okay no worries guys, I will gladly put together a bit of a walkthrough / explanation of how it works Link to comment
Floating.Point Posted November 1, 2021 Author Share Posted November 1, 2021 Okay so I posted a walkthrough for getting this set up here. I also found Andrews post about Alfred's 'Press Secretary' – which as mentioned could be a cleaner way to do all this. But then I also submitted a feature request to allow numeric keypad numbers to optionally bypass the requisite modifier – because I think these quick modals really could be useful to a broader audience. deanishe 1 Link to comment
deanishe Posted November 1, 2021 Share Posted November 1, 2021 5 hours ago, Floating.Point said: because I think these quick modals really could be useful to a broader audience Now that you've pointed it out, it seems so obvious that the keypad should work that way. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now