Jump to content
JimmyTheSaint

how to run workflow from command line?

Recommended Posts

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\"

 

Share this post


Link to post

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 by JimmyTheSaint

Share this post


Link to post

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 by deanishe

Share this post


Link to post

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?

Share this post


Link to post
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

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