folder action quicktime export to H.264

Hi,

I found this folder action script but I would like to modify it to:

  • let him check if there is new video file in the folder,
  • check if the copy of the file is done
  • if the copy is done, convert the original video file to H.264 in a folder (which is specified in the applescript) with the name of the original file.

I will really appreciate if somebody could help me.

Eric


global CurrentFileSize, LastFileSize, StillBusy, StillGrowing
on adding folder items to this_folder after receiving added_items
   try
       -- get the name of the folder
       tell application "Finder"
           set the folder_name to the name of this_folder
           -- find out how many new items have been placed in the folder
           set the item_count to the number of items in the added_items
       end tell
       ProcessAddedItems(this_folder, added_items, item_count)
   end try
end adding folder items to

on ProcessAddedItems(this_folder, added_items, item_count)
   -- loop through the files looking for finished files to process
   repeat with x from item_count to 1 by -1
       set File2Check to (item x of added_items) as string
       set AppleScript's text item delimiters to ":"
       set TheFileName to text item -1 of File2Check
       set AppleScript's text item delimiters to ""
       set LastFileSize to -1
       set Ready2Rock to false
       beep
       
       --loop waiting for the file to finish writing
       repeat until Ready2Rock is true
           -- modify the path accordingly - point to isDone().scpt on your machine
           set testResults to run script alias "mac osX:Library:Scripts:isdone.scpt" with parameters {File2Check, LastFileSize}
           set CurrentFileSize to item 2 of testResults
           if item 1 of testResults is true then
               set Ready2Rock to true
           else
               set LastFileSize to CurrentFileSize
           end if
           delay 1
       end repeat
       
       -- now that the file has finished writing,
       -- process the file while it's in this folder
       -- because the file is so big
       
       tell application "QuickTime Player"
           activate
           open added_items
           try
               if not (exists movie 1) then error "No movies are open."
               
               stop every movie
               
               -- CHECK FOR THE CORRECT VERSION
               set QT_version to (QuickTime version as string)
               set player_version to (version as string)
               if (QT_version is less than "5.0") or ¬
                   (player_version is less than "5.0") then
                   error "This script requires QuickTime 5.0 or greater." & ¬
                       return & return & ¬
                       "Current QuickTime Version: " & QT_version & return & ¬
                       "Current QuickTime Player Version: " & player_version
               end if
               
               -- CHECK FOR QUICKTIME PRO
               if QuickTime Pro installed is false then
                   set the target_URL to "http://www.apple.com/quicktime/download/"
                   display dialog "This script requires QuickTime Pro." & return & return & ¬
                       "If this computer is currently connected to the Internet, " & ¬
                       "click the "Upgrade" button to visit the QuickTime Website at:" & ¬
                       return & return & target_URL buttons {"Upgrade", "Cancel"} default button 2
                   ignoring application responses
                       tell application "Finder"
                           open location target_URL
                       end tell
                   end ignoring
                   error number -128
               end if
               
               -- get the name of the movie
               set the movie_name to the name of movie 1
               -- check to see if the opened movie can be exported
               if (can export movie 1 as DV stream) is true then
                   -- prompt the user for a name and location
                   set the new_file to ¬
                       choose file name with prompt "Enter a name and choose a location for the new file:" default name movie_name
                   -- export the movie as DV stream movie
                   export movie 1 to new_file as DV stream using settings preset "NTSC 44.1 kHz"
                   -- close the movie
                   close movie 1
               else
                   error "This movie cannot be exported as a DV stream."
               end if
           on error error_message number error_number
               if the error_number is not -128 then
                   beep
                   display dialog error_message buttons {"Cancel"} default button 1
               end if
           end try
       end tell
   end repeat
end ProcessAddedItems