Page 1 of 2

Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Thu Jan 24, 2013 9:25 am
by cmellor
Hello,

I want to be able to run an embedded script when a new file is detected in my Media folder.

I have a script called 'MKVDTS2AC3.sh' which is located in my 'home' directory (/Users/Chris/mkvdts2ac3/mkvdts2ac3.sh) and I have symlinked it to '/usr/local/bin'.

In Terminal and iTerm, this runs great, I just run:
Code: Select all
mkvdts2ac3.sh -n -i -f <path to media file>
and it runs, no problem.

Naturally I would assume that the same code would work in the Embedded Script. But no, I just keep getting errors. I cannot post the errors at the moment as I am at work, but I can do later.

Has anybody had any problems before with this script, or a similar situation?

Thanks.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Thu Jan 24, 2013 1:57 pm
by a_freyer
you must specify full paths for embedded scripts; including any binaries you call within your script.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Thu Jan 24, 2013 3:53 pm
by cmellor
Hi,

So I tried using full paths (I think).

I am confused about the Shell: bin/sh box. Does that matter a lot? I tried changing it to bin/bash to see if that did anything, but no.

From the Log, this is the error I get when a rule is detected.
Code: Select all
2013-01-24 19:41:50.561 hazelworker[642] Processing folder Films (forced)
2013-01-24 19:41:52.568 hazelworker[642] test.mkv: Rule Convert DTS to AC3 matched.
2013-01-24 19:41:52.643 hazelworker[642] [Error] Shell script failed: Error processing shell script on file /Volumes/Media/Films/test.mkv.
2013-01-24 19:41:52.643 hazelworker[642] Shellscript exited with non-successful status code: 1

For the shell script, I am using this.
Code: Select all
~/mkvdts2ac3/mkvdts2ac3.sh -n -f $1

This shows the full path to the .SH file, (this can also be accessed at /usr/local/bin, does that matter at all?)

Is this enough info to guess what the problem might be?

Many thanks.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Thu Jan 24, 2013 4:10 pm
by a_freyer
Even within the shell script, you have to supply full paths for most binaries. Echoing out the errors might help identify what the problem is:

Also, put $1 in quotes.

Code: Select all
~/mkvdts2ac3/mkvdts2ac3.sh -n -f "$1" 2>&1 >"~/Desktop/HazelErrors.txt"

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Thu Jan 24, 2013 4:26 pm
by cmellor
Hmmm...

I tried your suggestion and it didn't work, but it also didn't create the .txt file on the Desktop. Is it anything to do with write permissions?

As my Shell script says it is pointing to /bin/sh is that correct?

I'm pretty sure I've specified the full path for where the script is... isn't '~/' classed as the root?

Error wise on the Log... it's still exactly the same error.

Thanks again.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Thu Jan 24, 2013 4:31 pm
by a_freyer
This user has the same problem with the same script, but I don't see a resolution to the problem. the problem.

Send me the script and I'll see if I can get it running.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Fri Jan 25, 2013 11:36 am
by a_freyer
Ok, there are six binaries that are required for this to operate:

Dependencies wrote:mkvmerge
mkvextract
mkvinfo
ffmpeg
rsync
perl


Each and every one of these requires a full path every time it is called. One way to do this is:

1. Replace each with global variable:

Search for each name, replace all with $theName_binary: mkvextract -> $mkvextract_binary

2. Add to the '#default values' section:

Code: Select all
mkvmerge_binary=$(which mkvmerge)
mkvextract_binary=$(which mkvextract)
mkvinfo_binary=$(which mkvinfo)
ffmpeg_binary=$(which ffmpeg)
rsync_binary=$(which rsync)
perl_binary=$(which perl)


I don't see any more non-standard binaries in the file, we should be good to go if you make these replacements.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Fri Jan 25, 2013 11:53 am
by cmellor
Hey,

Thanks for taking a look. I will be trying this as soon as I get home from work and I will report back.

Just do I understand correctly...

Do I add that code to my embedded script inside the program? Or do I do that inside the script file (the .sh) itself? OR to the ~/.mkvdts2ac3.rc config file that it includes?

Like I say I'll try it when I get home and report back.

Thanks for your time on this.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Fri Jan 25, 2013 11:55 am
by a_freyer
All of the above suggested edits are within the MKVDTS2AC3.sh file itself.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Fri Jan 25, 2013 5:40 pm
by cmellor
*sigh*

So after I've edited the script as advised. I can only confirm that the script works in Terminal, but not in Hazel. I am getting the exact same script errors as before, with the status of [b]1]/b].

I am using this code in the embedded script:
Code: Select all
/Users/Chris/mkvdts2ac3/mkvdts2ac3.sh -n "$1"

But still no luck.

I tried it with:
Code: Select all
/Users/Chris/mkvdts2ac3/mkvdts2ac3.sh -n --test "$1"

which runs the script as normal but doesn't execute anything. That didn't run the script and just said the rule had being matched... so I'm wondering if it is actually seeing it?

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Fri Jan 25, 2013 5:49 pm
by a_freyer
To confirm, you have done this, yes?:
Code: Select all
chmod +755 /Users/Chris/mkvdts2ac3/mkvdts2ac3.sh

To make the script executable?

What do the Hazel logs say the error is? Just the same thing as above, with "non zero status"?
I've been presuming that you're matching to the MKV file that you want to convert, right?

Any changes if you look for errors?


Code: Select all
echo "$(/Users/Chris/mkvdts2ac3/mkvdts2ac3.sh -n -f "$1" 2>&1)" >> "HazelErrors.txt"

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Fri Jan 25, 2013 6:45 pm
by cmellor
I've CHMOD the file.

I added that echo statement and it generated a text file and I got this:

Code: Select all
usage: which [-as] program ...
usage: which [-as] program ...
ERROR: The program '' is not in the path. Is  installed?

Which makes me think I haven't edited the file properly. Though doing that was a bit intimidating. I wasn't 100% sure what to edit, I just did a 'Find & Replace'.

As I asked before... I don't suppose you have the script with the edited parts in it? (assuming you tested it at all)

Thanks.

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Fri Jan 25, 2013 6:49 pm
by a_freyer
No, I didn't edit the file myself. Send me yours and I'll check it?

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Fri Jan 25, 2013 6:56 pm
by a_freyer
Oh, you know what? I know where at least one of those is coming in. Replace the checkdep function:

Code: Select all
# Usage: checkdep appname
checkdep() {
   if [ -z "$1" ]; then return; fi #this will ignore any null path requests
   if [ -z "$(which $1)" -o ! -x "$(which $1)" ]; then
      error $"The program '$1' is not in the path. Is $1 installed?"
      exit 1
   fi
}

Re: Embedded Script Will Not Run - MKVDTS2AC3

PostPosted: Sun Jan 27, 2013 12:13 pm
by a_freyer
SOLVED Offline via email with OP.

Solution:

The which command does not function as expected within a Hazel shell, so the suggestion that I made above does not actually work. What does is simply specifying the actual path of each binary and adding an exception to the checkdep function.

e.g.

Code: Select all
$rsync_binary="/usr/bin/rsync"