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!



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.



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:



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:





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.

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