Jump to content
Sign in to follow this  
steviebraga

passing argument to ruby script

Recommended Posts

Hi guys,

 

I'm trying to create a simple alfred workflow (Keyword -> Run Script -> Post Notification) using ruby. If I run this scripts in the terminal, it runs just fine, but when I try to run them on Alfred, I get some errors:

ruby start.rb {query}
[ERROR: alfred.workflow.action.script] Code 1: -e:1:in `<main>': undefined local variable or method `start' for main:Object (NameError)

I assumed that ruby wasn't in Alfred path so I tried

/usr/bin/ruby start.rb {query}

and got this error:

[ERROR: alfred.workflow.action.script] Code 1: -e:1: unknown regexp option - b
-e:1: syntax error, unexpected tIDENTIFIER, expecting keyword_do or '{' or '('
/usr/bin/ruby start.rb asda
If I use double quotes on the script name i get this errors:
ruby "start.rb" {query}
[ERROR: alfred.workflow.action.script] Code 1: -e:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input
and
/usr/bin/ruby "start.rb" {query}
[ERROR: alfred.workflow.action.script] Code 1: -e:1: unknown regexp option - b
-e:1: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '('
/usr/bin/ruby "start.rb" asda
               ^
-e:1: syntax error, unexpected tIDENTIFIER, expecting end-of-input
 
Can someone enlighten me why this is happening?
 
Thanks!

Share this post


Link to post

A few things:

 

1. Alfred isn't running scripts from the command-line. There is no shell environment present, only the GUI environment. So your executable paths aren't present. Even when you run a bash script, bash is being started and stopped with the GUI environment as a non-login shell.

 

2. Any scripts you run using a relative path, e.g., 'start.rb', must be in the workflow directory. Otherwise you need to give the absolute path to the script.

 

3. You can run Ruby (and Python and Perl and Applescript) directly by putting in the code window and choosing the appropriate language from the dropdown.

 

4. The Ruby you're running is the system Ruby, not one you may have installed using RVM (or other tool).

 

5. In general when you're passing the {query} to a script or command you want to double quote it. And then check the Escape Double Quotes script option. Basically, whatever you're wrapping the {query} in needs to be escaped, e.g., backticks, etc.

Edited by ctwise

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.

Sign in to follow this  
×
×
  • Create New...