JBR Posted June 10, 2013 Share Posted June 10, 2013 Is it possible to restrict a hotkey to be active only when a particular application is in the foreground? The default implementation of hotkeys in Alfred's workflows causes all hotkeys to be 'global' in scope, which is to say that they work regardless of what application is running. For example, I'd like to run an apple script using the hotkey combination 'command+D' when Adobe Illustrator is in the foreground. Currently, setting this hotkey in Alfred achieves my purpose, however it also overrides the same hotkey combination in other apps that already use it, such as the 'duplicate' command in Finder. What I'd like is for 'command+D' to continue functioning as is when Finder is in the foreground, and make it run my apple script when Illustrator is in the foreground. Appreciate any feedback or ideas! Tyler Eich and Jay 2 Link to comment
Carlos-Sz Posted June 10, 2013 Share Posted June 10, 2013 (edited) You can check if AI is the top most application using the code below then execute the script if appName is AI. tell application "System Events" to set appName to item 1 of (get name of processes whose frontmost is true) Edited June 10, 2013 by Carlos-Sz Link to comment
JBR Posted June 21, 2013 Author Share Posted June 21, 2013 (edited) @Carlos-Sz: Thank you for the suggestion! Although I suppose this might be possible to implement outside of Alfred (perhaps with Automator?), it doesn't work within Alfred using a hotkey defined by Alfred. From what I can tell, as soon as a hotkey is defined within Alfred, it ceases to function within all other apps whether or not anything else is added to the workflow. (E.g. defining the hotkey 'command+D' within Alfred, in an otherwise empty workflow, causes the 'duplicate' command within Finder to no longer be available.) Even within a 'disabled' workflow, if a hotkey is defined, it is no longer available within other apps. Am I correct that this is an inherent limitation of Alfred? Edited June 21, 2013 by JBR Jay 1 Link to comment
Tyler Eich Posted June 21, 2013 Share Posted June 21, 2013 Is it possible to restrict a hotkey to be active only when a particular application is in the foreground? The default implementation of hotkeys in Alfred's workflows causes all hotkeys to be 'global' in scope, which is to say that they work regardless of what application is running. For example, I'd like to run an apple script using the hotkey combination 'command+D' when Adobe Illustrator is in the foreground. Currently, setting this hotkey in Alfred achieves my purpose, however it also overrides the same hotkey combination in other apps that already use it, such as the 'duplicate' command in Finder. What I'd like is for 'command+D' to continue functioning as is when Finder is in the foreground, and make it run my apple script when Illustrator is in the foreground. Appreciate any feedback or ideas! I like this idea a lot Say I have a workflow that only interfaces with certain applications (e.g. browsers); instead of getting frustrated with code that checks which app is in the foreground, Alfred automatically blocks or allows my workflow's hotkeys based on which app he detects is frontmost. This concept could be extended to any input (hotkeys, keywords, script filters, file filters, etc.). Say you have several script filters, each with the keyword 'tabs'; one filter's scope is 'Safari' & 'Webkit', another's is 'Chrome' & 'Chrome Canary' & 'Chromium', and another's is 'Camino'. When Chrome is active, typing 'tabs' into Alfred launches only the code necessary to get Chrome's tabs; when in Safari, a different code base is used. Scoping could be applied to an entire workflow or individual objects Context-aware workflows would be incredibly powerful and extend Alfred's intelligence +1 for this idea (if you couldn't tell from my comments ) Jay and smarg19 2 Link to comment
Empyreal Posted September 28, 2013 Share Posted September 28, 2013 I have just recently purchased the Powerpack because of the Gawker article on Alfred workflows. Great community here, and I think it will continue to be better as new functions are added to the foundation of Alfred. Scoping Hotkeys is one of these bits of functionality. Quicksilver has it, albeit it had been broken for a while, it is working again. Since installing Alfred, I'm definitely impressed, and at initial consideration, it seems like this is the most used feature of Quicksilver that I'm missing. Jay 1 Link to comment
Jay Posted September 29, 2013 Share Posted September 29, 2013 +1. I recently switched from Quicksilver, and this is the one feature I immediately miss. I have a group of applescripts that duplicate some of the text editing shortcuts of Sublime Text, but they're not as good as the native ST shortcuts, so I don't want to override them while using ST. Otherwise very impressed so far, keep up the great work! Jay 1 Link to comment
deanishe Posted February 6, 2014 Share Posted February 6, 2014 This is exactly what FastScripts and Keyboard Maestro are designed to do (application-specific keyboard shortcuts). Anyone looking to do something along these lines, should check them out. Keyboard Maestro in particular is insanely powerful (e.g. open Calibre when you connect your Kindle). Link to comment
avendael Posted March 16, 2014 Share Posted March 16, 2014 +1. I bought a powerpack for this feature, only to find out there is none Link to comment
Andrew Posted March 16, 2014 Share Posted March 16, 2014 While I haven't completely ruled out hotkey scopes, it adds significant complexity to the implementation of hotkeys and as such, will make Alfred much more active at idle. I do have a ticket to consider this. Cheers, Andrew 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