How can I make the script output the encoded file in a user defined directory?

I'm trying to build an in-house media file encoder based on Automator and ffmpeg.

I want the source file(s) to be dropped on the app's icon and then ask the user where to output the encoded files.

So far I have an Automator app where I drop files onto it and it runs this AppleScript:

    on run {input, parameters}

    tell application "Terminal"
        set filesString to ""
        repeat with file_ in input
            set filesString to filesString & " " & quoted form of (POSIX path of file_)
        end repeat
        do script "for f in" & filesString & "; do

ffmpeg -i \"$f\" -c:v copy -an ${f%.*}_264.mp4

    end tell
    return input
end run

Currently the app outputs the encoded file at the same directory as the input file.

How can I make Automator ask the user for and use a destination directory?

  • What is your question? May 28 '15 at 9:20
  • I think you should have your question be reflected in the Title as well. Good luck!
    – myhd
    May 28 '15 at 9:54

Automator - 'Ask for Finder Items'

You should probably want to clean up your code. Now you are using and AppleScript and Automator and BASH.

Anyway, in Automator you can ask for a location, store that variable and use it later in your Shell script. You can 'stack' variables in an array by concatenating 'Get Value of Variable'.

Example code and screenshot:

# all input arguments
echo "${@}"

# The 'Output location' is the first in the stack
echo "Output folder location: ""$1"

# Loop through the remaining arguments
for f in "${@:2}"
    echo "Video file:""$f"

automator example

  • In your example, how would this command go: ffmpeg -i var1 -c:v copy -an var2. How would I pass these two variables?
    – o_ren
    May 28 '15 at 13:59
  • You can 'stack' variables in an 'array'. I've updated my example. May 28 '15 at 14:27
  • Thanks @CousinCocaine. I adjusted your example to my needs and sure got a very good lesson.
    – o_ren
    May 31 '15 at 14:51

You must log in to answer this question.

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