|
|
#1 |
|
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 |
|
|
|
|
|
#2 |
|
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 |
|
|
|
|
|
#3 |
|
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 |
|
|
|
|
|
#4 |
|
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 |
|
|
|
|
|
#5 | |||||||||||||||||||
|
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)
__________________
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 |
|||||||||||||||||||
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,946
|
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 |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|