Jump to content
JBR

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!

Share this post


Link to post
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

Share this post


Link to post

@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

Share this post


Link to post

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)

Share this post


Link to post

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.

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...