Force Fetch to "wait" for Quicktime export ??

So I have 2 scripts that need to be combined into one. But the second requires that the process initiated by the first is complete before it attempts to run. So the first half of the script looks into a folder, finds the newest file (a QT movie) inside the folder and then exports a new video into a new location. No problem…so far looks like this:

set theFolder to alias "Macintosh HD:" --The folder holding the ORIGINAL Quicktime movie

tell application "Finder"
	set fileList to every document file of theFolder -- or which class you prefer
	set newest_file to first item of (sort fileList by creation date) -- or modification date
end tell

tell application "QuickTime Player"
	open newest_file
	
	with timeout of 30000 seconds
		export movie 1 to file (path to desktop & "New Movie" & ".mov") as QuickTime movie
	end timeout
	
	close movie 1 saving no
	delay 5
	quit "Quicktime Player"
	
end tell

Then once the file has been completely exported I need Fetch 4.0.3 to retrieve the newest file of the destination folder and upload this file to an FTP server. So this 2nd half so far looks like this:

set theDesktop to path to desktop

tell application "Finder"
	set fileList to every document file of theDesktop -- or which class you prefer
	set newest_export to first item of (sort fileList by modification date) as alias -- or creation date
	
	
	--Uploads the newest file to the appropriate remote directory
	
	tell application "Fetch 4.0.3"
		activate
		with timeout of 30000 seconds --will affect only the file upload
			
			put into url "FTP INFO HERE" item newest_export
			
		end timeout
		quit
	end tell
end tell

display dialog "File Uploaded." buttons "OK" default button "OK"

So in the above example, there is a QT movie at the root (“Macintosh HD”). QT will open the newest file (to be generate once daily) and export it to the desktop. Fetch will scan the desktop for the newest file THERE and upload it. These are not going to be the actuall file locations/destinations but that’s irrelevant. I’m trying to keep my “example” above simple.

So…the question is: How best to have Fetch wait for the QT Export process to be done? With a timeout? If you notice in the first script (the QT export) that it calls for QT to QUIT once done. Maybe Fetch can use an “if ‘System Event’ Quicktime Player”… to see if QT is even running before it tries to proceed? And have it proceed only if QT is NOT running?

Thanks in advance for any input in this matter.
Kevin

My fave is this:


to IsSizeStable(myFile) -- can be a folder too
	-- initialize the loop
	set Size_1 to 0
	set Size_2 to 1
	-- repeat until sizes match
	repeat while Size_2 ≠ Size_1 --  loop until they're equal
		set Size_1 to Size_2 -- new base size
		delay 3 --wait three seconds, or whatever
		set Size_2 to size of (info for myFile) -- get a newer size
	end repeat -- once the sizes match, the download is done
end IsSizeStable


I like the looks of your script. It looks like to me that it is basically watching the file size of the exported movie and as long as this size is increasing, other processes are on hold.

So how then do I combine my 2 halves with your chunk. My 2nd half needs to “wait” on the first half to be done. So how does the marriage of the 3 work?

Thanks, KB

-- set theFolder to alias "Macintosh HD:" --The folder holding the ORIGINAL Quicktime movie
set theDesktop to path to desktop

tell application "Finder"
	set fileList to every document file of theFolder -- or which class you prefer
	set newest_file to first item of (sort fileList by creation date) -- or modification date
end tell

tell application "QuickTime Player"
	open newest_file
	with timeout of (10 * minutes) seconds
		export movie 1 to file (theDesktop & "New Movie" & ".mov") as QuickTime movie
	end timeout
	close movie 1 saving no
	delay 5
	quit "Quicktime Player"
end tell

isSizeStable(newest_file) -- this will not return until size is stable

(* The following is commented out because I don't have Fetch *)

--Uploads the newest file to the appropriate remote directory

(*	tell application "Fetch 4.0.3"
		activate
		with timeout of 30000 seconds --will affect only the file upload
			
			put into url "FTP INFO HERE" item newest_export. Use "newest_file" as file to upload
			
		end timeout
		quit
	end tell *)


display dialog "File Uploaded." buttons "OK" default button "OK"

to isSizeStable(myFile) -- can be a folder too
	-- initialize the loop
	set Size_1 to 0
	set Size_2 to 1
	-- repeat until sizes match
	repeat while Size_2 ≠ Size_1 --  loop until they're equal
		set Size_1 to Size_2 -- new base size
		delay 3 --wait three seconds, or whatever
		set Size_2 to size of (info for myFile) -- get a newer size
	end repeat -- once the sizes match, the download is done
end isSizeStable