Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've installed the Perian addon for Quicktime so it can open .flv files, and then I can save them as .m4v or .mov. I'm trying to make an Applescript to convert from .flv to .m4v automatically by using this tutorial and butchering their example applescript file, which normally converts ChemDraw files (.cdx, .cml, .mol) to .tiff, so that it instead uses Quicktime to save the .flv files as .m4v. When I try to use it, though, I get an error "QuickTime Player got an error: document 1 doesn't understand the save message". My save message is currently:

save first document in target_path as ".m4v"

which looks like the QuickTime dictionary's instructions:

save specifier : The document(s) or window(s) to save.

[as saveable file format] : The file format to use.

I've also tried "m4v", without the period, and still get the error.
Is my Save direction wrong, or is it probably an error from trying to use Quicktime instead of the original ChemDraw? I tried to change references to .cdx, .cml, .mol, .tiff, and ChemDraw to .flv, .m4v, and QuickTime respectively, but maybe it's more complicated than that?

share|improve this question
    
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.. –  Brett Johnson Dec 26 '10 at 0:12
1  
You 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 Dec 29 '10 at 10:37
    
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 –  Brett Johnson Dec 30 '10 at 3:40
1  
It's probably a good idea to follow up on your questions and the answers provided, if you want to get a solution. –  Daniel Beck Jan 2 '11 at 9:20
add comment

4 Answers

You can always resort to UI scripting. Taking @Benny's answer as a basis, here's what works (somewhat):

set infile to choose file with prompt "select file:"
set outfile to "filename"

try
    tell application "QuickTime Player"
        activate
        close every window
        open infile
        delay 2 # wait for the document to open
        tell application "System Events"
            keystroke "s" using {command down, shift down} # press Cmd-Shift-S
            delay 1 # wait for the sheet
            keystroke outfile # the filename
            key code 36 # press enter
        end tell
        close document 1 saving no
    end tell
end try

If you want to simply save something in TextEdit as per your comment, you can use the following as a basis:

set infile to choose file with prompt "select file:"
set outfile to choose file name with prompt "Save altered file here:"

tell application "TextEdit"
    activate
    open infile
    tell application "System Events" # just some keystrokes for edits
        keystroke "AppleScript was here!"
        key code 36 # press enter
    end tell
    tell document 1 to save in outfile
    close every document saving no
end tell

If you want to save a document as a specific file type, there seems to be an issue with the as parameter: I couldn't get it to save in one of the selectable formats. You can circumvent the issue by specifying the desired file extension, e.g. filename.html or filename.odt for Web Page and OpenDocument formats respectively.

share|improve this answer
add comment

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
share|improve this answer
add comment

The Applescript script described here might be useful : QuickTime Export Droplet.

Although this doesn't answer your question, here are two commercial products which seem to be a solution, with trials available:

Wondershare iPad Video Converter for Mac ($25)
Video Converter for Mac ($39)

share|improve this answer
    
The purpose isn't really to make a converter, but more to learn how to, so this doesn't really help- thanks though. –  Brett Johnson Dec 30 '10 at 3:18
    
See the first sentence of my edited answer. –  harrymc Dec 30 '10 at 10:40
add comment

I don't know if this works but try,

set infile to choose file with prompt "select file:"
set outfile to choose file name with prompt "Save altered file here:"

try
tell application "QuickTime Player"
activate
close every window
open infile
set dimensions of document 1 to {720, 400}
tell document 1
save self contained file outfile
end tell
-- save document 1 given «class dfil»:file outfile, «class savk»:self contained
close document 1 saving no
end tell
end try

See if that works.

If that dosen't work see this page. http://discussions.apple.com/thread.jspa?threadID=1055811

share|improve this answer
    
nope, no dice; it doesn't like "contained" –  Brett Johnson Dec 30 '10 at 3:16
    
I don't know if it will work but try removing "contained" –  Benny Dec 30 '10 at 8:13
    
It doesn't work because back in 2007, there was no QuickTime X. This is for the old, legacy, QuickTime Player 7, where there was a commercial QuickTime Pro. –  Daniel Beck Dec 30 '10 at 11:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.