luckman212 Posted November 20, 2019 Share Posted November 20, 2019 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...) Link to comment
luckman212 Posted November 23, 2019 Author Share Posted November 23, 2019 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=29456https://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: 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now