Jump to content
luckman212

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

Share this post


Link to post

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.

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