JimmyTheSaint Posted April 21, 2018 Posted April 21, 2018 I'm trying to run a workflow from a Terminal command line in preparation to use Sleepwatcher to run that workflow every time I close the lid. But apparently I don't have things quoted and escaped correctly, and I can't figure it out. Can I get some correction on the following? $ /usr/bin/osascript -e tell application \"Alfred 3\" to run trigger \"MyExternalTrigger\" in workflow \"com.jimmy34742.alfred.MyWorkflow\"
deanishe Posted April 21, 2018 Posted April 21, 2018 You need to quote the entire AppleScript: "tell application ...
JimmyTheSaint Posted April 22, 2018 Author Posted April 22, 2018 (edited) Thanks for taking a look. That is indeed one of the variations I'd tried. When I do: /usr/bin/osascript -e 'tell application \"Alfred 3\" to run trigger \"AstrillToggle-ext\" in workflow \"com.jimmy34742.alfred.AstrillToggle\"' Terminal returns: syntax error: Expected expression, property or key form, etc. but found unknown token. (-2741) I've gone over it with a fine tooth comb, but I don't see any typos. I have several workflows that I've made external triggers for, and they work fine. When I run the workflow from Alfred, it works correctly. Edited April 22, 2018 by JimmyTheSaint
JimmyTheSaint Posted April 22, 2018 Author Posted April 22, 2018 When I do it without adding the single quotes as you suggested, I get this expected error: syntax error: Expected expression but found end of script. (-2741)
deanishe Posted April 22, 2018 Posted April 22, 2018 (edited) I used a double quote, not a single quote. Quoting arguments is a precise business (because shell's are stupid), and you need to pay close attention. The whole point of the backslash is to escape the following character. There's no need to escape double quotes unless they're within other double quotes, and it's most likely broken if you do. Either use: /usr/bin/osascript -e "tell application \"Alfred 3\" to run trigger \"MyExternalTrigger\" in workflow \"com.jimmy34742.alfred.MyWorkflow\"" or /usr/bin/osascript -e 'tell application "Alfred 3" to run trigger "MyExternalTrigger" in workflow "com.jimmy34742.alfred.MyWorkflow"' Edited April 22, 2018 by deanishe
JimmyTheSaint Posted April 22, 2018 Author Posted April 22, 2018 Yes, that worked, thanks. I see my mistake now: I cut and pasted from my Karabiner.json where the call to Alfred's workflow is in fact inside double quote, necessitating escaping the nested double quotes. But it still doesn't work as expected. When I do: $ /usr/bin/osascript -e 'tell application "Alfred 3" to run trigger "AstrillToggle-ext" in workflow "com.jimmy34742.alfred.AstrillToggle"' it opens Alfred's window with the workflow ready to run, and I still have to hit the return key to execute the workflow. How do I make that command line directly execute the workflow without opening Alfred's window and waiting for user input?
deanishe Posted April 22, 2018 Posted April 22, 2018 3 hours ago, JimmyTheSaint said: necessitating escaping the nested double quotes Yes, but if you got it from a JSON file, then the command was escaped for JSON. In this case (double quotes), it's the same as shell escaping, but bear in mind that what works in JSON doesn't necessarily work in a shell. 3 hours ago, JimmyTheSaint said: But it still doesn't work as expected That's exactly how it's supposed to work. 3 hours ago, JimmyTheSaint said: I still have to hit the return key to execute the workflow You can simulate a press of the return key: tell application "System Events" to key code 36
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