Running shell script in Hazel

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Running shell script in Hazel Mon Dec 03, 2012 6:28 pm • by jarhead
I blog using Octopress which creates static HTML from markdown files and then uploads the files to my web host.

In Terminal, I run
Code: Select all
cd /Users/doug/octopress
which then displays "Using /Users/doug/.rvm/gems/ruby-1.9.3-p327 with gemset octopress"

I then type
Code: Select all
rake generate && rake deploy
which correctly generates the static HTML files & uploads them via rsync to my web host. This all works correctly from Terminal.

However, I cannot get it to run in Hazel.

Image

I'm assuming I'm missing something simple or Hazel requires something different. Can anyone point me in the right direction? Thanks.
jarhead
 
Posts: 12
Joined: Mon Dec 03, 2012 2:55 pm

Re: Running shell script in Hazel Tue Dec 04, 2012 10:18 am • by jarhead
After reviewing info on running shell scripts, I note that if I run an external script, I can trigger a script already on my disk. So I created the following named octo.sh that is executable:

Code: Select all
#!/bin/bash

cd /Users/doug/octopress
rake generate


When my rule is run, I'm notified via Growl that there was an error processing shell script. I'm assuming Hazel stores the errors but I'm not sure where to find it.

Also, I'm missing something as the cd & rake commands run correctly in terminal.

Any help greatly appreciated. Thanks.
jarhead
 
Posts: 12
Joined: Mon Dec 03, 2012 2:55 pm

Re: Running shell script in Hazel Tue Dec 04, 2012 2:39 pm • by a_freyer
Hazel logs shell script outputs in its own log. I'd suggest checking there for more information. Post back and we'll see if we can help.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Running shell script in Hazel Tue Dec 04, 2012 2:54 pm • by Mr_Noodle
Just to elaborate, go to Hazel's "Info" section and click "View Log". As for the script, one thing to try is to use fully specified paths to any executables.
Mr_Noodle
Site Admin
 
Posts: 11247
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Running shell script in Hazel Tue Dec 04, 2012 5:15 pm • by jarhead
a_freyer wrote:Hazel logs shell script outputs in its own log. I'd suggest checking there for more information. Post back and we'll see if we can help.


Thanks. I assumed as much but I was unsure where to find the log.

Running the script embedded per my first post gives me...

Code: Select all
2012-12-04 15:02:41.195 hazelworker[29189] [Error] Shell script failed: Error processing shell script on file /Users/doug/octopress/source/_posts/2012-12-04-my-awesome-post.markdown.
2012-12-04 15:02:41.195 hazelworker[29189] Shellscript exited with non-successful status code: 1


It looks as though it's trying to run the script on the actual file versus just running the rake generate command like when running via Terminal.
jarhead
 
Posts: 12
Joined: Mon Dec 03, 2012 2:55 pm

Re: Running shell script in Hazel Tue Dec 04, 2012 5:19 pm • by jarhead
Mr_Noodle wrote:Just to elaborate, go to Hazel's "Info" section and click "View Log". As for the script, one thing to try is to use fully specified paths to any executables.


Thanks for the help on finding the log. Since the file I'm using is Ruby and it's file name is entitled Rakefile, I'm not sure how to specify the path. The location of the file is in → /users/doug/octopress hence the reason I cd into the folder.

Typing rake generate or rake deploy executes correctly in Terminal.
jarhead
 
Posts: 12
Joined: Mon Dec 03, 2012 2:55 pm

Re: Running shell script in Hazel Tue Dec 04, 2012 5:27 pm • by a_freyer
On my system, we have this:

Code: Select all
/usr/bin/rake


If that does not work, type this in terminal:

Code: Select all
usernames-macbook:~ username$ whereis rake
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Running shell script in Hazel Tue Dec 04, 2012 6:23 pm • by jarhead
I went the easier route and just created an Applescript that launches Terminal, hides the window, runs the script and closes Terminal after a set period of time. This works perfectly.

Out of curiosity, how would you reference /usr/bin/rake in Hazel to run rake generate inside /users/doug/octopress?

Thanks.
jarhead
 
Posts: 12
Joined: Mon Dec 03, 2012 2:55 pm

Re: Running shell script in Hazel Tue Dec 04, 2012 6:32 pm • by a_freyer
jarhead wrote:I went the easier route and just created an Applescript that launches Terminal, hides the window, runs the script and closes Terminal after a set period of time. This works perfectly.

Out of curiosity, how would you reference /usr/bin/rake in Hazel to run rake generate inside /users/doug/octopress?

Thanks.



Wow... haha. That is not what I would call the "easy" way at all. What'd you'd do is specify the path for rake:

Code: Select all
#!/bin/bash
cd /Users/doug/octopress
/usr/bin/rake generate
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Running shell script in Hazel Tue Dec 04, 2012 6:44 pm • by jarhead
a_freyer wrote:
Wow... haha. That is not what I would call the "easy" way at all. What'd you'd do is specify the path for rake:

Code: Select all
#!/bin/bash
cd /Users/doug/octopress
/usr/bin/rake generate


Thanks but that did not work embedded or as a standalone script.

Seems pretty easy to me and it works...

Code: Select all
tell application "Terminal"
   do script "cd /users/doug/octopress;rake generate && rake deploy"
   close front window
   delay 30
   quit
end tell
jarhead
 
Posts: 12
Joined: Mon Dec 03, 2012 2:55 pm

Re: Running shell script in Hazel Tue Dec 04, 2012 6:47 pm • by a_freyer
Then you'll likely need to specify the paths for your rakefiles in that directory. But, if you're happy with your solution there's no real reason to edit it I suppose.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Running shell script in Hazel Tue Dec 04, 2012 6:52 pm • by jarhead
Happy only because the solution works. I would definitely rather have it run as a shell script.

Can you provide more info when you say "specify the paths for your rakefiles in that directory"? I know enough to get me in trouble when it comes to Terminal so I always enjoy learning. Thanks.
jarhead
 
Posts: 12
Joined: Mon Dec 03, 2012 2:55 pm

Re: Running shell script in Hazel Tue Dec 04, 2012 7:09 pm • by a_freyer
jarhead wrote:Happy only because the solution works. I would definitely rather have it run as a shell script.

Can you provide more info when you say "specify the paths for your rakefiles in that directory"? I know enough to get me in trouble when it comes to Terminal so I always enjoy learning. Thanks.


I don't have your octopress setup to test, but generally speaking you can find lots of good information in the manual entry of the executable you're trying to run:

Code: Select all
usernames-macbook:~ username$ man rake


This tells me, among other things, that appending a -f lets me specify the rakefile. So, you're probably looking at something like this:

Code: Select all
/usr/bin/rake -f /Users/doug/octopress/rakefile.rb generate


Your rakefile might just be called rakefile without the ruby extension. It also may be case sensitive.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Running shell script in Hazel Tue Dec 04, 2012 7:10 pm • by a_freyer
I'd mess around with adding a specific path in terminal first. It's way easier than trying to force Hazel to run each and every time you change a single character in the embedded script.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Running shell script in Hazel Wed Dec 05, 2012 11:25 am • by jarhead
a_freyer wrote:I'd mess around with adding a specific path in terminal first. It's way easier than trying to force Hazel to run each and every time you change a single character in the embedded script.


I've tried multiple options all that run successfully in Terminal but continue to fail in Hazel both as embedded and stand alone scripts.

In Terminal, once I cd into /users/doug/octopress, the following two scripts run correctly...

Code: Select all
/usr/bin/rake -f /Users/doug/octopress/rakefile generate


Code: Select all
/Users/doug/.rvm/gems/ruby-1.9.3-p327@global/bin/rake generate


Running the first script (embedded & stand alone) in Hazel, this is displayed in log file...

2012-12-05 08:50:19.427 hazelworker[36006] Shellscript exited with non-successful status code: 1


Running the second script (embedded & stand alone) in Hazel, this is displayed in log file...

2012-12-05 08:45:15.517 hazelworker[35735] Shellscript exited with non-successful status code: 127


Would love to figure this out. Any more ideas? Thanks for the recommendations.
jarhead
 
Posts: 12
Joined: Mon Dec 03, 2012 2:55 pm

Next

Return to Support