Do Shell Script Won't Work, but works in terminal. MKVPROPEDIT

Hi Everybody.
I have this script that works if i run the script in the end, directly in terminal, but if i try from do shell script it won’t work.
i can’t specify the path to mkvpropedit, since i can’t find it.
Here is the script:
set theFile to choose file
tell application “Finder”
set theName to get name of theFile
set theName to text 1 thru ((offset of “.” in theName) - 1) of theName
set theQName to quoted form of theName
set thepath to ((container of (theFile) as text) & theName)
set thePosFile to ((POSIX path of thepath) & “.mkv”)
set thePosFile to quoted form of thePosFile
end tell

set theScript to “mkvpropedit " & thePosFile & " --edit info --set title=” & theQName

i have tried this instead and it works, but i would like something that just runs in the background.
tell application “Terminal”
activate
do script theScript
delay 0.1
close front window
end tell

Thanks in advance

Hello.

display alert (do shell script "echo $PATH") with title "From do shell script"

tell window 1 of application "Terminal"
	do script "echo $PATH"
end tell

Seems like the Terminal knows, so type in Terminal:

whereis mkvpropedit

What McUsr is trying to say here is that Terminal and do shell script doesn’t share the same shell variables, or at least not always the same values. $PATH is a variable in shell which contains the path to binaries (commands) so you don’t have to type the whole path to the command but only the name of the command. You can check if bash can find a file with the whereis commands.

do shell script "whereis mkvpropedit"

Does it return a path or an empty string? When it returns an empty string it means that the file can’t be found. If you type the same command in the terminal and you have path you have found your problem.

If both the terminal command and the shell script return the same paths you have another problem. Another difference between the terminal and do shell script is that by default do shell script uses sh instead of bash and do shell script is an non-interactive shell while terminal is using an interactive shell. That can easily be fixed by adding bash -i -c in front of the command.

Hello.

When you have found the mkvpropedit file, then just add that path in front of it, to the do shell script command.

I think which mkvpropedit, or which -a mkvpropedit, should work as well for revealing the executable in Terminal.

Your code is :

set theFile to choose file
tell application "Finder"
    set theName to get name of theFile
    set theName to text 1 thru ((offset of "." in theName) - 1) of theName
    set theQName to quoted form of theName
    set thepath to ((container of (theFile) as text) & theName)
    set thePosFile to ((POSIX path of thepath) & ".mkv")
    set thePosFile to quoted form of thePosFile
end tell

set theScript to "mkvpropedit " & thePosFile & " --edit info --set title=" & theQName

This does not solve the problem but I wish to point the fact that your code is generating several a non-fatal error -10004 because it calls the feature offset belonging to the OSAX Standard Additions inside a tel application block.
A cleaner code would be :

set theFile to choose file
tell application "Finder"
	set theName to get name of theFile
	set theContainer to container of theFile as text
end tell
set theName to text 1 thru ((offset of "." in theName) - 1) of theName
set theQName to quoted form of theName
set thepath to theContainer & theName
set thePosFile to ((POSIX path of thepath) & ".mkv")
set thePosFile to quoted form of thePosFile

set theScript to "mkvpropedit " & thePosFile & " --edit info --set title=" & theQName

For my own use I won’t trigger the Finder to extract theName and theContainer but it’s an other story.

Yvan KOENIG (VALLAURIS, France) mardi 26 août 2014 16:05:56