Page 1 of 1

Processing a Terminal command

PostPosted: Tue Jun 26, 2012 12:56 am
by papo
This is a rule I have setup with an AppleScript because I had no luck using any other methods. As you can tell from the screenshot below, I am trying to encode files as they come in, but I don't want all of them to encode at once. (Want it to work like a queue.. finish one file, then on to the next)

Image

The problem with this, is that multiple Terminal windows are opened when multiple files match the criteria.

I need for Hazel to wait on Terminal to finish encoding one file, before moving on the to the next file.

I don't want to use the delay feature, because the encoding times can vary. Some can take 5 minutes, some 12 hours.

Can you please help?

Re: Processing a Terminal command

PostPosted: Tue Jun 26, 2012 6:24 pm
by a_freyer
Why aren't you doing this with an embedded shell script?

This is not the way to do what you're looking for. Just do this and you won't see multiple terminal windows:

Code: Select all
encode-handheld.pl -pbIM -m4 -t appletv -pbIM -f $1


This will run in a queue, but it will possibly stop Hazel from working for many of your other rules (since it will wait until each script is done.).

I'd recommend doing this:

Code: Select all
encode-handheld.pl -pbIM -m4 -t appletv -pbIM -f $1 >/dev/null 2>&1 &


By sending 2>&1 we redirect all errors to standard output and all standard output to null. The ampersand forks, and returns immediately.

This will run all conversions in parallel without effecting Hazel. If you really want these to be processed in a queue, I'd suggest moving one file at a time (via rule) into a 'conversion only' folder.

Re: Processing a Terminal command

PostPosted: Tue Jun 26, 2012 7:21 pm
by papo
a_freyer wrote:Why aren't you doing this with an embedded shell script?

This is not the way to do what you're looking for. Just do this and you won't see multiple terminal windows:

Code: Select all
encode-handheld.pl -pbIM -m4 -t appletv -pbIM -f $1



This is exactly what I was trying to do at first, but it did not work for me. :(

I will try again. With regards to Hazel being held up while it waits for the process to finish, I am fine with that.


This is the error I get:

Code: Select all
6/26/12 7:27:10.122 PM [0x0-0x29c29c].com.noodlesoft.HazelHelper: /var/folders/pr/r_bqmvm53jvgncjkzhby61qw0000gn/T/hazelworker-8527/hazelscript.sh: line 1: encode-handheld.pl: command not found


But this works fine if I run it in terminal.

Re: Processing a Terminal command

PostPosted: Tue Jun 26, 2012 7:38 pm
by papo
a_freyer wrote:Why aren't you doing this with an embedded shell script?

This is not the way to do what you're looking for. Just do this and you won't see multiple terminal windows:

Code: Select all
encode-handheld.pl -pbIM -m4 -t appletv -pbIM -f $1



This is exactly what I was trying to do at first, but it did not work for me. :(

I will try again. With regards to Hazel being held up while it waits for the process to finish, I am fine with that.


This is the error I get:

Code: Select all
6/26/12 7:27:10.122 PM [0x0-0x29c29c].com.noodlesoft.HazelHelper: /var/folders/pr/r_bqmvm53jvgncjkzhby61qw0000gn/T/hazelworker-8527/hazelscript.sh: line 1: encode-handheld.pl: command not found


But this works fine if I run it in terminal.



When I used this, I get the following on the logs:

Code: Select all
/usr/local/bin/encode-handheld.pl -pbIM -m4 -t appletv -pbIM -f $1


Code: Select all
6/26/12 7:31:12.418 PM System Preferences: Unknown action value type: applescript
6/26/12 7:31:36.655 PM System Preferences: Unknown action value type: shellscript
6/26/12 7:31:53.406 PM [0x0-0x29c29c].com.noodlesoft.HazelHelper: I'm out of ideas where ffmpeg could be and I'm not about to search for it.
6/26/12 7:31:53.406 PM [0x0-0x29c29c].com.noodlesoft.HazelHelper: Please adjust the location of ffmpeg in this script.
6/26/12 7:31:53.424 PM GrowlHelperApp: ---
6/26/12 7:31:53.424 PM GrowlHelperApp: Hazel: Hazel Alert (test success) - Priority 0
6/26/12 7:31:53.426 PM GrowlHelperApp: Reserving rect NSRect: {{970, 707}, {300, 61}}
6/26/12 7:31:53.429 PM GrowlHelperApp: Push priority level is: High - 1
6/26/12 7:31:53.429 PM GrowlHelperApp: Not pushing because notification does not match the priority level.

Re: Processing a Terminal command

PostPosted: Tue Jun 26, 2012 7:45 pm
by a_freyer
Prepending the full path was my next suggestion but it looks like you've already done that.

Seems like 'encode-handheld.pl' is looking for your installation of ffmpeg - you'll have to adjust the file location within the script, as it suggests.

I'd suggest running in terminal a "where ffpeg" command to determine its path. It should be in /usr/local/bin/ffmpeg

Re: Processing a Terminal command

PostPosted: Tue Jun 26, 2012 7:51 pm
by papo
that's exactly where it's located. How can I put this into the shell script?

sorry... i am trying my best. not a programmer/coder. I appreciate your help!!

Re: Processing a Terminal command

PostPosted: Tue Jun 26, 2012 8:52 pm
by a_freyer
Hmmm... well I'm not sure why your script isn't functioning then. I'd suggest opening it is text edit and looking for ffmpeg

From terminal, you can do it like this:

Code: Select all
open -a TextEdit /usr/local/bin/encode-handheld.pl

Re: Processing a Terminal command

PostPosted: Tue Jun 26, 2012 8:56 pm
by a_freyer
I just found a version of your script online, and at least according to this one from 2008 the location of ffpeg on darwin (read: mac) is named with a version number.

Again, I don't know if this specifically applies in your case. Just look for hardcoding of the path for ffmpeg in your version of the perl script

Fix the hardcoding and you should be ready to go.

Code: Select all
.....
# Some hard coded locations where I have ffmpeg and AtomicParsley on my Linux and Mac OS computers
if ( $Config{osname} eq "linux" ) {
   $ffmpeg = "/usr/local/bin/ffmpeg";
        $atomicparsley = "/usr/local/bin/AtomicParsley";
   $jhead = "/usr/bin/jhead";
} elsif ( $Config{osname} eq "darwin" ) {
   $ffmpeg = "/usr/local/bin/ffmpeg-r20921";
   $atomicparsley = "/usr/local/bin/AtomicParsley";
   $jhead = "/usr/bin/jhead";
}
...


Change:

$ffmpeg = "/usr/local/bin/ffmpeg-r20921";

to

$ffmpeg = "/usr/local/bin/ffmpeg";



And you'll be good to go:


Code: Select all
.....
# Some hard coded locations where I have ffmpeg and AtomicParsley on my Linux and Mac OS computers
if ( $Config{osname} eq "linux" ) {
   $ffmpeg = "/usr/local/bin/ffmpeg";
        $atomicparsley = "/usr/local/bin/AtomicParsley";
   $jhead = "/usr/bin/jhead";
} elsif ( $Config{osname} eq "darwin" ) {
   $ffmpeg = "/usr/local/bin/ffmpeg";
   $atomicparsley = "/usr/local/bin/AtomicParsley";
   $jhead = "/usr/bin/jhead";
}
...

Re: Processing a Terminal command

PostPosted: Tue Jun 26, 2012 9:01 pm
by papo
Ok. Yea.

Going to test it now.

Re: Processing a Terminal command

PostPosted: Wed Jun 27, 2012 1:15 pm
by a_freyer
After a lengthy IM chat with this user, we found that reinstalling Hazel worked, installing for all users.

Re: Processing a Terminal command

PostPosted: Thu Jun 28, 2012 3:14 pm
by papo
I mean to post back findings sooner, but a very special thanks to "a_freyer" for helping me troubleshoot the issue.

I really appreciate your help and want to say thanks once again. You spent a lot of time helping me.