I’m trying to create a droplet which will run a shell script. However, I need to pass two variable to the shell script. I’d like the variable to be determined by the two files which are dropped on it. It should only allow one .ttxt file and one .mp4 file to be processed. Below is the non-droplet test version. This works as far as the shell script is concerned.
set binPath to "/usr/local/bin/" as string
set theVideo to POSIX path of "/Volumes/Scratch HD/MP4Encode/everify_icegov.mp4"
set theText to POSIX path of "/Volumes/Scratch HD/MP4Encode/captions/everify.ttxt"
set theNew to POSIX path of "/Volumes/Scratch HD/MP4Encode/"
do shell script binPath & "mp4box -add '" & theVideo & "' -add '" & theText & "' -new '" & theNew & "everify_subs_shell.mp4'"
I’ve seen a bunch of posts on variable from droplets but can’t quite get it to work. I keep getting a “class<>” error.
Hi,
assuming that theText and theVideo are supposed to represent the two dropped files, try this
on open theseItems
if (count theseItems) is not 2 then return -- abort the script if the number of dropped files is not 2
set {theVideo, theText} to {missing value, missing value}
repeat with anItem in theseItems
tell (anItem as text)
if it ends with "ttxt" then
set theText to it
else if it ends with "mp4" then
set theVideo to it
end if
end tell
end repeat
-- abort the script if there is no ttxt and mp4 file
if theVideo is missing value or theText is missing value then return
set mp4boxPath to "/usr/local/bin/mp4box"
set mp4EncodeFolder to "/Volumes/Scratch HD/MP4Encode/"
do shell script mp4boxPath & " -add " & quoted form of POSIX path of theVideo & ¬
" -add " & quoted form of POSIX path of theText & " -new " & quoted form of (mp4EncodeFolder & "everify_subs_shell.mp4")
end open
Your assumption was correct.
That worked perfectly!
One change I made was to set the destination folder to a “choose folder” When I did that I got:
Can’t make quoted form of {alias “xxxxxxx”, filename.mp4} into type Unicode text.
The xxxxx is the path to my selected destination folder.
choose folder returns an alias specifier, for the shell you have to coerce it first to POSIX path
set destinationFolder to POSIX path of (choose folder)
set destinationFile to quoted form of (destinationFolder & "filename.mp4")
Perfect. Thanks so much.
On running this, I discovered that using the “quoted form of the POSIX path” would not yield the correct results from the shell script. Instead I had to included the single quotes as quoted text, if that makes sense. By that I mean by final shell script call looked like this:
do shell script mp4boxPath & " -add '" & POSIX path of theVideo & ¬
"' -add '" & POSIX path of theText & "' -lang [2=english] -new '" & destinationFolder & "file.m4v'"
Thanks again for the assistance!
Back to the well…
I’ve lost the last 2 hours trying to figure this out: I want to base the name of the destination file on the name of theVideo file. Basically, if I’m giving it video.mp4, I want it to create video_subtitle.mp4. I know how to add the _subtitle. The problem I’m having is pulling the file name from the path to the file. Also, I think the loop is creating special issues I’m not aware of, because I keep getting “file not found” errors, among others.
Here is where I’ve left off. You’ll see what I attempted in the commented lines under “set theVideo”
on open theseItems
if (count theseItems) is not 2 then return -- abort the script if the number of dropped files is not 2
set {theVideo, theText} to {missing value, missing value}
repeat with anItem in theseItems
tell (anItem as text)
if it ends with "ttxt" then
set theText to it
else if it ends with "mp4" then
set theVideo to it
--set {name:fileName, name extension:nameExtension} to info for theVideo
--set baseName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
set {isFolder, theName, ext} to {folder, name, name extension} of (info for theVideo)
if ext is not "" then set theName to text 1 thru ((count theName) - (count ext) - 1) of theName
end if
end tell
end repeat
-- abort the script if there is no ttxt and mp4 file
if theVideo is missing value or theText is missing value then return
set mp4boxPath to "/usr/local/bin/mp4box"
set destinationFolder to POSIX path of (choose folder)
do shell script mp4boxPath & " -add '" & POSIX path of theVideo & ¬
"' -add '" & POSIX path of theText & "' -new '" & destinationFolder & baseName & "_subtitled.m4v'"
end open
Thank you.