Jump to content

Adding 'scopes' to Hotkeys


Recommended Posts

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!

Link to comment
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 by Carlos-Sz
Link to comment
  • 2 weeks later...

@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 by JBR
Link to comment

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  :D)

Link to comment
  • 3 months later...

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.

Link to comment

+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!

Link to comment
  • 4 months later...

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
  • 1 month later...

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