Björn
Björn

Reputation: 71

Send command to terminal with AppleScript

I have this ffmpeg command that I would like to send to terminal through appelscript. It works when I run it directly in terminal.

ffmpeg -i score.mov -i palette.png -filter_complex \
"fps=8,scale=600:-1:flags=lanczos[x];[x][1:v]paletteuse" -f image2pipe -vcodec ppm - | convert -delay 15 -loop 0 -layers Optimize - output39.gif

This doesn't compile in scripteditor.

tell application "Terminal"
    do script "ffmpeg -i score.mov -i palette.png -filter_complex \
"fps=8,scale=600:-1:flags=lanczos[x];[x][1:v]paletteuse" -f image2pipe -vcodec ppm - | convert -delay 15 -loop 0 -layers Optimize - output39.gif"
end tell

I get "Expected end of line but found identifier"

Anyone have an idea what to do?

Upvotes: 0

Views: 685

Answers (2)

vadian
vadian

Reputation: 285190

Use do shell script – as suggested in the other answer – , delete the line separators and replace the double quotes in the string with single quotes.

do shell script "ffmpeg -i score.mov -i palette.png -filter_complex 'fps=8,scale=600:-1:flags=lanczos[x];[x][1:v]paletteuse' -f image2pipe -vcodec ppm - | convert -delay 15 -loop 0 -layers Optimize - output39.gif"

Upvotes: 2

EricDAltman
EricDAltman

Reputation: 71

You're close but have some definite syntax issues.

You don't have to tell Terminal, first of all.

The proper syntax in AppleScript for shell commands is: "do shell script" followed by the command. Remember you are sending text to this function, so properly escape out the " and ' and $ and what not in your script with double \\'s as to not confuse the script.

For future consistency sake, I like to set all shell applications I utilize to properties at the beginning of my app:

property grep : do shell script "which grep"

...then recall them in my script lines, but that isn't necessary.

Try this:

do shell script "ffmpeg -i score.mov -i palette.png -filter_complex \
\\"fps=8,scale=600:-1:flags=lanczos[x];[x][1:v]paletteuse\\" -f image2pipe \
-vcodec ppm - | convert -delay 15 -loop 0 -layers Optimize - output39.gif"

Upvotes: 1

Related Questions