This answer is hella long because your comments seem to indicate that your main interest is AppleScript itself, not converting videos from FLV to MP4. If this is the case, I strongly recommend starting with a good AppleScript reference, reading carefully and learning to use the tools available to you (especially Script Editor and application dictionaries). Trying to learn a new language by modifying existing applications is not good for debugging and can end in very bad things like cargo cult programming. That said,
I'd start by opening QuickTime Player's dictionary (
File->
Open Dictionary... in Script Editor) to see what commands are available. In my version of QuickTime Player (7.6.4), there's an
export
command in the QuickTime Player Suite:
export v : Export a movie or track to a file
export reference : the movie or track to export
to file : the destination file
as AIFF/Apple TV/AVI/BMP/DV stream/Fast Start QTVR Movie/FLC/hinted
movie/image sequence/interframe compressed VR object movie/iPhone/
iPhone cellular/iTunes/MuLaw/MPEG2/MPEG4/picture/QuickTime media
link/QuickTime movie/QuickTime TeXML/standard MIDI/System 7 sound/
text file/ThreeGPP/wave : the desired file type
[using default settings/most recent settings] : the export settings
to use
[using settings preset string] : the name of the export settings
preset to use
[using settings file] : the file containing the export settings
[replacing boolean] : should the original file be deleted first?
A little Googling suggests that the "iPhone" file type refers to a .m4v file, so a first step might be replacing save first document in target_path as ".m4v"
with export first document to target_path as iPhone
. Looking through the dictionary a little more, though, shows that there's also a can export
command:
can export v : Determine if a movie or track can be exported to the desired
type
can export reference : the movie or track to export
as AIFF/Apple TV/AVI/BMP/DV stream/Fast Start QTVR Movie/FLC/hinted
movie/image sequence/interframe compressed VR object movie/iPhone/
iPhone cellular/iTunes/MuLaw/MPEG2/MPEG4/picture/QuickTime media
link/QuickTime movie/QuickTime TeXML/standard MIDI/System 7 sound/
text file/ThreeGPP/wave : the desired file type
→ boolean : is the export supported
So we should check that it's possible to export the movie in iPhone/.m4v format before actually doing so:
if (can export first document as iPhone) then
export first document to target_path as iPhone
else
error "Cannot export " & (source_file as string) & " in .m4v (iPhone) format."
end if
If we stop here, though, we may notice that some of the output files don't play correctly beyond a certain point, because QuickTime can load files asynchronously (i.e., not all at once). We should try to check that QuickTime Player has finished loading a movie before we tell it to export; by examining the full list of load states listed in the dictionary and assuming that every movie eventually ends up in a finished state or an error state, we can add this relatively easily.
set error_states to {load state unknown, load error}
set successful_states to {loaded, complete}
repeat until load state of first document is in (error_states & successful_states)
delay 0.1
end repeat
if (load state of first document is in successful_states) then
if (can export first document as iPhone) then
export first document to target_path as iPhone
else
error "Cannot export " & (source_file as string) & " in .m4v (iPhone) format."
end if
else
error "File is not in a successful load state: " & (load state of first document as string)
end if
In fact, I would settle for a simple example applescript showing how to save a file using TextEdit or something, since I haven't been able to save any sort of file yet.. – None – 2010-12-26T00:12:50.417
1You will perhaps get more feedback from stackexchange as I see this as a script programming issue. There are more than 550 applescript-related issues at the moment over there. – LudoMC – 2010-12-29T10:37:56.193
Could you actually link an applescript-related stackexchange post, as I can't seem to find any, and it looks like "applescript" isn't even an existing tag yet. I've re-posted here
– None – 2010-12-30T03:40:40.4701It's probably a good idea to follow up on your questions and the answers provided, if you want to get a solution. – Daniel Beck – 2011-01-02T09:20:45.050