Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Using Automator for app to create .ISO

Hello,


I have a very useful Applescript for using ffmpeg to convert video files. Of course within that script is a Terminal script for actually running ffmpeg.

It looks like this:


on run {input, parameters}

tell application "Terminal"

activate

set filesString to ""

repeat with file_ in input

set filesString to filesString & " " & quoted from of (POSIX path of file_)

end repeat

do script "for f in" & filesString & "; do

/Users/Mike/Documents/Scripts/ffmpeg -i \"$f\" -acodec pcm_s16le -vcodec v210 -level 1 -coder 1 -context 1 -g 1 -qscale 0 ${f%.*}.mov

end tell

return input

end run



It works really well to just drop a file onto the app and have it run. But now I want to create ISO images from DVDs that I have created in the past. The script above looks for the input path and makes in the output path of the new file with the same name. I want to do a couple of different things.


First, I obviously can't return the new file to the DVD but I'm not sure how to change the script correctly, but I've highlighted where I think it probably needs to change. Additionally I would like a user prompt to choose a destination. I was really close with:


"set myPath to choose folder with prompt "choose a folder:"


It would be nice to both set the path and the filename at that point.

I also really like that I can see the progress of the ISO creation in Terminal.


I am taking a very basic course to learn Applescript but I'm just not quite there yet. Help please?

Mac OS X (10.6.8), null

Posted on Apr 19, 2016 3:49 PM

Reply
Question marked as Best reply

Posted on Apr 20, 2016 9:55 AM

I have a couple of observations...


There's nothing inherently wrong with your script - it's essentially gathering all the data, then firing off a single shell command to do the work. The problem is that to extend the functionality to the point of creating an .iso, you need to do that within the shell command.


An alternative (easier - at least for an experienced AppleScripter) path would be to minimize the shell command to the bare minimum (i.e. process an individual file), and use AppleScript to handle the looping and variables. For example, instead of building one string of files and passing that to one shell command that iterates over it, I'd do something more like:


tell application "Terminal"


activate

repeat with file_ in input

set filesString to quoted form of (POSIX path of file_)

do script "/Users/Mike/Documents/Scripts/ffmpeg -i " & fileString & " -acodec pcm_s16le -vcodec v210 -level 1 -coder 1 -context 1 -g 1 -qscale 0 " & fileString & ".mov"

end repeat

end tell

Now you have each specific file in an AppleScript variable (file_), which is passed in to a shell command that executes your command. Multiple input files just invoke the shell command multiple times. This also makes it easier to add processing per file


As for the other question - selecting the output file name/location, just replace your 'choose folder' with 'choose file name'. This will allow the user to specify a file name and directory using the standard UI, from which you can extract the data you want:


repeat with file_ in input


-- this works out the input file's name:

tell application "System Events"

set inputFilename to name of (get properties of file_)

end tell



-- prompt the user for where this file should be saved

set outputFile to choose file name with prompt "Specify output file name for " & inputFilename


set inputFilePath to quoted form of (POSIX path of file_)

set outputFilePath to quoted form of (POSIX path of outputFile)


tell application "Terminal"


activate

do script "/Users/Mike/Documents/Scripts/ffmpeg -i " & inputFilePath & " -acodec pcm_s16le -vcodec v210 -level 1 -coder 1 -context 1 -g 1 -qscale 0 " & outputFilePath

end tell

end repeat

Note also that I've separated the code into more logical (to me, at least) chunks... I've separated out the application logic regarding the input and output files, and just target Terminal.app with the specific command(s) that are relevant to it.

From here you can easily incorporate additional 'do script' commands to do whatever you want, using the same variables to map the input and output file names.

2 replies
Question marked as Best reply

Apr 20, 2016 9:55 AM in response to RachMusicMan

I have a couple of observations...


There's nothing inherently wrong with your script - it's essentially gathering all the data, then firing off a single shell command to do the work. The problem is that to extend the functionality to the point of creating an .iso, you need to do that within the shell command.


An alternative (easier - at least for an experienced AppleScripter) path would be to minimize the shell command to the bare minimum (i.e. process an individual file), and use AppleScript to handle the looping and variables. For example, instead of building one string of files and passing that to one shell command that iterates over it, I'd do something more like:


tell application "Terminal"


activate

repeat with file_ in input

set filesString to quoted form of (POSIX path of file_)

do script "/Users/Mike/Documents/Scripts/ffmpeg -i " & fileString & " -acodec pcm_s16le -vcodec v210 -level 1 -coder 1 -context 1 -g 1 -qscale 0 " & fileString & ".mov"

end repeat

end tell

Now you have each specific file in an AppleScript variable (file_), which is passed in to a shell command that executes your command. Multiple input files just invoke the shell command multiple times. This also makes it easier to add processing per file


As for the other question - selecting the output file name/location, just replace your 'choose folder' with 'choose file name'. This will allow the user to specify a file name and directory using the standard UI, from which you can extract the data you want:


repeat with file_ in input


-- this works out the input file's name:

tell application "System Events"

set inputFilename to name of (get properties of file_)

end tell



-- prompt the user for where this file should be saved

set outputFile to choose file name with prompt "Specify output file name for " & inputFilename


set inputFilePath to quoted form of (POSIX path of file_)

set outputFilePath to quoted form of (POSIX path of outputFile)


tell application "Terminal"


activate

do script "/Users/Mike/Documents/Scripts/ffmpeg -i " & inputFilePath & " -acodec pcm_s16le -vcodec v210 -level 1 -coder 1 -context 1 -g 1 -qscale 0 " & outputFilePath

end tell

end repeat

Note also that I've separated the code into more logical (to me, at least) chunks... I've separated out the application logic regarding the input and output files, and just target Terminal.app with the specific command(s) that are relevant to it.

From here you can easily incorporate additional 'do script' commands to do whatever you want, using the same variables to map the input and output file names.

Using Automator for app to create .ISO

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.