I want to create an AppleScript app with this perfectly working (bash) command:

cd /Volumes/MEDIAS/WORK/CONVERSION_VIDEO/PROXY_720P/INPUT/; for f in *.mov *.mp4; do ffmpeg -i "$f" -vcodec prores -profile:v 0 -s 1280x720 /Volumes/MEDIAS/WORK/CONVERSION_VIDEO/PROXY_720P/OUTPUT/"${f%.*}_PROXY_720P.mov" && rm "$f"; done

but I get errors with the variable "$f".

How can I launch it through AppleScript?

  • Welcome to AskDifferent! Consider rewriting your question so that it sticks to one topic - right now you have two - how to run a bash command in AppleScript and a problem with the variable expansion of f. What error are you getting and what specifically would you like to know?
    – Allan
    Dec 21, 2016 at 22:21

2 Answers 2


Shell scripts/commands in AppleScript are handled with the do shell script command, which executes a shell script using the sh shell. In the short form of:

do shell script "..."

Where ... is the shell script to execute.

See AppleScript Language Guide do shell script Commands Reference and Technical Note TN2065 do shell script in AppleScript, for additional details.

What you need to do, is escape the double-quotes with a backslash, e.g. \"$f\" and elsewhere as necessary.

I've tested your command, wrapped in a do shell script command, with the necessary escaping as shown in the command below and it worked without issue.

do shell script "cd /Volumes/MEDIAS/WORK/CONVERSION_VIDEO/PROXY_720P/INPUT/; for f in *.mov *.mp4; do ffmpeg -i \"$f\" -vcodec prores -profile:v 0 -s 1280x720 /Volumes/MEDIAS/WORK/CONVERSION_VIDEO/PROXY_720P/OUTPUT/\"${‌​f%.*}_PROXY_720P.mov‌​\" && rm \"$f\"; done"

Note: Because the do shell script command uses the sh shell, if the ffmpeg executable is not in the PATH passed to the shell, which is /usr/bin:/bin:/usr/sbin:/sbin, you'll need to include the fully qualified pathname to the ffmpeg executable for your command to work in AppleScript.


The direct parameter of the do shell script command is a string containing the shell code you want to execute, as demonstrated in Listing 39-1, which simply lists a directory.


Open in Script Editor Listing 39-1AppleScript: Executing a simple shell command that lists the contents of a directory

do shell script "ls /Applications/"
--> Result:
"App Store.app

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .