Scripting with Quicktime X - Help and comments welcomed

I’ve been using scripts with Quicktime for a while now but with Quicktime X and OS 10.6 things don’t work the same.
What I like about Quicktime X is it’s simplicity. There are not many options and the options that there are work well and fast. I tend to post a lot of Quicktime movie files for work and there’s always a need to support a variance of download and upload speeds.
I normally start with an uncompressed Quictime and make the compressed versions from there. This ‘versioning’ tends to grow into quite a lot of work with a many Quicktime movie files as sources.
I started on this script that is meant to take a folder of uncompressed Quicktime movie files and duplicate it in another location whilst also making the various compressed versions.
I’ve hit a snag or two. The largest one Quicktime X’s seemingly lack of support to scripting, the other a file naming issue where removing the extension from a filename is not working.
Any insight/help/recommendations are much appreciated.

V.

Here’s my script:



-- define export presets as listed in Quicktime X :
property moviePreset1 : "iPhone"
property moviePreset2 : "HD 480p"
property moviePreset3 : "HD 720p"
property moviePreset4 : "HD 1080p"
property ext1 : "_iPhone"
property ext2 : "_480p"
property ext3 : "_720p"
property ext4 : "_1080p"

-- define actions on run
on run
    -- ask for source folders
    choose folder with prompt "Choose SOURCE Folder(s):" with multiple selections allowed without invisibles
    open (result)
end run

-- define actions
on open droppedItems
    --ask for destination folder
    choose folder with prompt "Choose a DESTINATION Folder:"
    set exportFolder to result	
    repeat with thisFolder in droppedItems		
        get name of (info for thisFolder without size)
        try
            set importFolder to result
        end try
		
        tell application "Finder"
            -- check if folder exists
            if not (exists folder importFolder of exportFolder) then
                try
                    -- make a new folder with the same name as the source folder in the destination folder
                    make new folder at exportFolder with properties {name:importFolder}
                    -- define target folder
                    set targetFolder to result as Unicode text
                    on error errorMsg number errorNum
                    display dialog "Error (" & errorNum & "):" & return & return & errorMsg  ¬
                    buttons "Cancel" default button 1 with icon caution
                end try
            else
                -- we're not overwriting previously made folders nor incrementing
                display dialog "There is already a folder named  " & importFolder & " in " & exportFolder & return & ¬
                return & "Please rename or remove that folder first and try again" buttons {"Cancel"} default button 1
            end if
        end tell
		
        if (folder of (info for thisFolder without size)) is true then
            list folder thisFolder without invisibles			
            repeat with thisFile in (result)				
                tell application "QuickTime Player"
                    -- start the application
                    launch
                    -- open the movie file
                    set thisMovie to open ((thisFolder as Unicode text) & thisFile)
					
                    -- take the file extension off the filename (version 1)
                    # set AppleScript's text item delimiters to {"."}
                    # get name of (info for thisFile without size)
                    # try
                    #	set targetName to (text items 1 thru -2 of result) as text
                    # on error
                    #	set targetName to result
                    # end try
                    # set AppleScript's text item delimiters to {""}
					
                    -- take the file extension off the filename (version 2)
                    try
                        set the fileName to the name of thisFile
                        set fileExt to the name extension of thisFile
                        if the fileExt is "" then
                            set the trimmedName to the fileName
                        else
                            set the trimmedName to text 1 thru -((length of fileExt) + 2) of the fileName
                        end if
                        set targetName to trimmedName as Unicode text
                    on error
                        -- give up on removing the file extension
                        set targetName to thisFile
                    end try
                    -- save in new file
                    try
                    save thisMovie in ((targetFolder as Unicode text) & targetName & "_copy") with icon
                    -- the following does not work in Quicktime X ... Also, it could be cleaner.
                    save thisMovie as moviePreset1 in ((targetFolder as Unicode text) & targetName & ext1) with icon
                    save thisMovie as moviePreset2 in ((targetFolder as Unicode text) & targetName & ext2) with icon
                    save thisMovie as moviePreset3 in ((targetFolder as Unicode text) & targetName & ext3) with icon
                    save thisMovie as moviePreset4 in ((targetFolder as Unicode text) & targetName & ext4) with icon
                    end try
                    -- purge the open movie data
                    close thisMovie
                end tell				
            end repeat			
        end if
    end repeat	
end open


You have a few problems.

  1. when you try to get the file name without the extension you are telling quicktime to do that. Quicktime doesn’t know the command “name extension”. That’s a Finder command so you should be telling the Finder to do that part of your script. It will always error in its current form.

  2. When you save the files, you aren’t giving them a file extension so you need to add “.mov” to the end of their names.

  3. “with icon”… I never heard of that so I looked in the dictionary and there’s nothing about it in there… it probably does nothing

  4. you need to use “export” instead of “save” to convert the files. Your command needs to look something like this…

export thisMovie in ((destFolder as text) & "hank_iphone.mov") using settings preset "iPhone"

NOTE: QuicktimeX gives me problems when exporting. These export options work for me: iPod, iPhone, iPhone (Cellular). The following options actually perform the export but there’s no output file when the export finishes: HD 480p, HD 720p, HD 1080p. I’m not sure why???

NOTE: this may be good or bad but the applescript doesn’t pause and wait when you start an export. So if you start multiple exports they all run at the same time. Since you’re using a repeat loop you may be starting many, many exports all at once. You probably should put a mechanism in your script to pause until an export completes before you do another export. Or start a few exports and pause before you do more.

In conclusion, with the problems I see with QuicktimeX I would just use the old Quicktime Player 7 to do exports. It’s reliable.

EDIT:
I figured out why the HD 480p, HD 720p, HD 1080p export options didn’t work for me initially… because the source material wasn’t of a high enough quality. I used a high-quality source and that exported to those formats fine. It’s just weird that the lower quality source did actually go through the export process but when it was finished there was no ouput file for these formats. So everyone should be careful of that.