Go Back   The macosxhints Forums > Working with OS X > OS X Developer



Reply
 
Thread Tools Rate Thread Display Modes
Old 11-21-2006, 12:52 PM   #1
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
Scripting a "Greedy" program

Final Cut Pro is a monster CPU hog (even on a colleague's quad-core), and it's not AppleScriptable either. In spite of this, it can be GUI-scripted provided what you want to do can be handled by its menu choices and by keystroking text where required.

The problem with this is that while it's exporting a job, none of the standard tricks for detecting that the export is complete work e.g., checking visible windows for a progress bar times out without finding it, and waiting for the output file size to stabilize doesn't work because the Finder isn't getting time to update the file size even when commanded to do so.

Looking at a Terminal window running "top -U shortUname -o cpu -n 2" shows FCP gobbling cpu time all right, but how would I get that back to an AppleScript? Is there another way to have a shell script do this so the AppleScript would not proceed to the next instruction until FCP had completed the export?
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 11-21-2006, 01:07 PM   #2
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,941
Well you could just use 'do shell script' to look at the output file size.
E.g. something like this:
set size to first word of (do shell script "du /path/to/the/file")
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 11-21-2006, 01:44 PM   #3
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
That certainly works for anything but a package, but in a script like the one below, that would only work if the applescript got the time to run it. I'll ask my colleague to try it.

Code:
-- insert this command after the export command
checkStableSize(myFile) -- change to correct variable name

on checkStableSize(myFile)
	set sizeThen to first word of (do shell script "du " & POSIX path of myFile)
	repeat
		delay 1 -- seconds (set to longer if needed)
		set sizeNow to first word of (do shell script "du " & POSIX path of myFile)
		if sizeNow - sizeThen = 0 then exit repeat
		set sizeThen to sizeNow
	end repeat
end checkStableSize
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Old 11-21-2006, 04:02 PM   #4
hayne
Site Admin
 
Join Date: Jan 2002
Location: Montreal
Posts: 31,941
I recall a recommendation in the Apple tech note on 'do shell script' to use 'quoted form of' when using paths in 'do shell script'
__________________
hayne.net/macosx.html
hayne is offline   Reply With Quote
Old 11-22-2006, 08:09 AM   #5
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
Just for general interest, this works: (With thanks to Hayne for the suggestion. The character following -d is a zero)

Quote:
on checkStableSize(myFile)
set F to "'" & POSIX path of myFile & "'" -- note single quotes - absolutely necessary
set sizeThen to first word of (do shell script "du -d 0 " & F)
repeat
delay 1 -- seconds (set to longer if needed)
set sizeNow to first word of (do shell script "du -d 0 " & F)
if sizeNow - sizeThen = 0 then exit repeat
set sizeThen to sizeNow
end repeat
end checkStableSize

__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3

Last edited by NovaScotian; 11-22-2006 at 10:38 AM. Reason: Tweaked
NovaScotian is offline   Reply With Quote
Old 11-23-2006, 09:19 AM   #6
NovaScotian
Hall of Famer
 
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
Quote:
Originally Posted by NovaScotian
Just for general interest, this works: (With thanks to Hayne for the suggestion. The character following -d is a zero)

An even more reliable form - works on files or folders

Code:
-- insert this command after the cpu-eating command
checkStableSize(myItem) -- change to correct variable name
-- Use in the script after a brief delay to make sure the file is there.

-- Add this handler after main script.

-- Handler to wait until a file is fully loaded.
on checkStableSize(theItem)
	set F to quoted form of POSIX path of theItem
	set sizeThen to first word of (do shell script "du -d 0 " & F) as integer --coercing to integer fixes the quote problem
	repeat
		try
			delay 1 -- seconds (set to longer if needed)
			set sizeNow to first word of (do shell script "du -d 0 " & F) as integer --coercing to integer fixes the quote problem
			if sizeNow - sizeThen = 0 then exit repeat
			set sizeThen to sizeNow
		on error
			exit repeat
		end try
	end repeat
end checkStableSize
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3
NovaScotian is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 09:37 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.