Jump to content

Contact Action - branching based on modifier keys?


Recommended Posts

I have a custom Contact Action defined so I can trigger a workflow when I select Phone#s in Alfred. Works great!

image.png.e03853e4be359f1dcbef25da65ab3e5d.png

 

One thing is, I recently added a List Filter to the workflow so I can choose whether to DIAL (via my Asterisk based PBX) or TEXT (iMessage) the selected number. This also works great.

image.png.2bf9a69466fe1660eb0e83d58c911b08.png

 

However—99% of the time, I just want to DIAL and skip the List Filter step. It would be great if there was the ability to choose a different branch by holding a modifier like <SHIFT> (similar to what exists on Keyword or Script Filter objects). Is this possible to do any other way, or could this maybe added to an upcoming Alfred version? (if so please move this to Feature requests...)

Link to comment

I found a hacky way of doing it... based on research from these links:

https://brettterpstra.com/2012/08/05/quick-tip-checking-for-modifier-keys-in-shell-scripts/
https://macscripter.net/viewtopic.php?id=29456
https://stackoverflow.com/questions/7514280/get-modifier-keys-which-have-been-pressed-while-starting-an-app-applescript

 

I ran some timing tests, using Python vs. external compiled (Xcode11) CLI tool vs. AppleScript—Cached AppleScript running from a NSAppleScript object was the fastest and requires no external dependencies, so that wins for now. I think this still should be a native option in Alfred (branch from Contact Actions based on modifier keys) but for now, this achieves the goal:

 

image.png.20b1ad41b5b1bb263c72bf4ba3987503.png

 

NSAppleScript

use framework "Foundation"
use framework "AppKit"

on alfred_script(q)
  set cMod to current application's class "NSEvent"'s modifierFlags()
  set s to (cMod div 131072 mod 2 is 1)
  set outStr to (s & "|" & q) as text
  return outStr
end alfred_script

This will pass along a string into {query} in the format bool | arg

 

I then use Split Arg to Vars object to put the bool ("true" or "false") flag of the SHIFT key state into a workflow argument, which is later used in the conditional to branch accordingly.

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