Hey guys, I need to figure out a way to measure how much time it takes for a file to copy to a folder. I figured it could probably be written as a folder action, but I don’t know exactly how to go about doing it. I thought maybe have the script check the start time of when the file is added, check the file size every “x” amount of seconds. After the file size doesn’t change, read the time and subtract the original time? Any ideas?
I am not sure if this is quite what you’re looking for, but I use an Automator workflow fused with AppleScript to do the same thing. I have about 3 of these workflows, each one copying to a different location. This works well for my needs, but of course you could tweak it. Here’s how I have it set up:
Run AppleScript:
on run {input, parameters}
set startTime to (get current date)
set finalResult to "A file copy to dkschroeder-m-55's drop box was initiated at " & startTime & "."
set logFile to "Timed Copy Operations.txt"
set logName to ((path to documents folder as text) & logFile)
set fileRef to open for access file logName with write permission
write finalResult & return to fileRef as «class utf8» starting at eof
close access fileRef
return input
end run
Get Selected Finder Items
Copy Finder Items
(Show this action when workflow runs)
Run AppleScript:
on run {input, parameters}
set finalPath to input as text
set endTime to (get current date)
set finalResult to "The file copy to the network drop box ended at " & endTime & "."
set logFile to "Timed Copy Operations.txt"
set logName to ((path to documents folder as text) & logFile)
set fileRef to open for access file logName with write permission
write finalResult & return to fileRef as «class utf8» starting at eof
close access fileRef
return input
end run
This will create a log called “Timed Copy Operations.txt” in your Documents folder, and generate the start time. Then, it will copy the files currently selected in the Finder (when the workflow is launched) to the location you specify. Finally, it will paste the end time into the log. It wouldn’t be too tough to have it read the log and compare the times, but I didn’t want this for my needs.
Thanks. This is getting me much closer, but I am not there yet. This is going to eventually be a “Wait commmand” for finder. It’s a little detailed in to explain why I have to do this, but this is what I’m ultimately trying to accomplish.
- Read start time of file copied to folder or “X”
- copy file
- Read end time after file has been copied or “Y”
- Y-X= Z time difference
- Convert Z time into seconds format
- Multiple “Z” Sec X 3
- Tell finder to wait that many seconds before moving on.
I know if seems like a ridiculous thing.
Basically I have a working applescript that compresses a file to another folder. Finder waits until it is done copying before moving on by reading the file size of the destination folder.
I need to work with a new compression type. This compression goes through 3 passes, or compresses it 3 times.
The problem is that after the 1st pass, the file size doesn’t grow anymore. So the script moves on even though it still has 2 more passes to go.
SO I need to find out how many seconds it took for it to compress the 1st pass, and then multiply the wait time by 3 so it can finish compressing before moving on.
This is potentially not quite what you want, but you could probably make a repeat loop that checks if the process (of whatever compression type you are using) exists. If it does, then it would keep repeating; once the process no longer exists, it could move on in the script.
Hi,
you can check a stable size of a file with this handler
on checkStableSize(myFile) -- myFile can be a HFS string path, Finder file specifier or alias
set F to quoted form of POSIX path of (myFile as alias)
set sizeThen to first word of (do shell script "du -d 0 " & F)
delay 2 -- 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
return (sizeNow - sizeThen = 0) -- returns true if the size doesn't change, otherwise false
end checkStableSize
Here’s a more convinient way of measuring time since it already provides the seconds:
set startTime to do shell script "date +%s"
delay 2
set finishTime to do shell script "date +%s"
set overallTime to finishTime - startTime
Or
set StartTime to (current date)
delay 2
set ENDTime to (current date) - StartTime
I’m thinking this might be the best option. I just don’t know what the script format would be. I looked at my compressor (Cleaner 6.5.1) applications dictionary and I think one of the following three option commands might work:
[b]
- Start encoding
- Get encoder status
- batch item Status (Sometime I compress more the one file at a time)[/b]
I did some searching on other post and I found something similar. But in trying to convert it to what I need, it’s not quite working at all. This is what I have:
on ExportDone(compressing)
set isCompressing to "batch item status"
set isCurrentlyCompressing to check_cleaner_is_compressing()
if isCurrentlyCompressing is false then
else
quit
end if
end ExportDone
to check_cleaner_is_compressing()
delay 3
tell application "Cleaner 6.5.1"
if is_compressing then
return true
else
return false
end if
end tell
end check_cleaner_is_compressing
When I look at he original script I found, I see what it is doing, but I just can’t get it right working with my program Obvoiusly I would take out the shutdown command, because I want the script to move on to my next command which is to tell “cleaner 6.5.1” to quit when they are all done compressing:
on ExportDone(recordingID)
set isCurrentlyRecording to check_eyetv_is_recording()
if isCurrentlyRecording is false then
with timeout of 300 seconds
tell me to activate
display dialog "Warning: Export to iTunes complete. Your system will automatically shut down in 2 minutes unless you click Stop" with icon 0 buttons {"Stop"} giving up after 120 default button "Stop"
set theresults to the result
if gave up of theresults is true then
tell application "System Events" to shut down
end if
end timeout
else
quit
end if
end ExportDone
to check_eyetv_is_recording()
delay 10
tell application "EyeTV"
if is_recording then
return true
else
return false
end if
end tell
end check_eyetv_is_recording
Has the application Cleaner an is_compressing property in its dictionary?
You can’t simply “translate” terminology between applications. The classes and commands must exist in the dictionary
Well, if you didn’t already know, I have sold myself out at how horribly new to this I am. I did a little more searching in the “cleaner 6.5.1” dictionary and it looks like I have the following commands to work with"
Commands:
- GetEncodingStatus
- BatchItem Status
Properties:
EncodingStatus‚n
properties
ProcessingState (ProcessStopped/ProcessRunning/ProcessPaused/ProcessSleeping, r/o)
NumPasses (integer, r/o)
CurrentPass (integer, r/o)
PercentDone (real, r/o)
But I Don’t understand the difference between the two
Would the coding be something like:
Tell application "cleaner 6.5.1" to GetEncodingStatus
And then work out some kind of if/then command?
I don’t have the app, so I can’t test anything.
Does this compiile?
to check_cleaner_is_compressing()
delay 3
tell application "Cleaner 6.5.1"
return ProcessingState of GetEncodingStatus is ProcessRunning
end tell
end check_cleaner_is_compressing
I plugged it in to my current script I already have. It compiled, but nothing happened. It just does what the script normally did before I added your part of the script.
- Grabs file from folder.
- Sets the compression type
- Starts encoding to destination folder.
set myFolder to ((path to desktop folder as text) & "Render")
tell application "Cleaner 6.5.1" to activate
tell application "Cleaner 6.5.1" to Clear
tell application "Finder"
set Afolder to (myFolder) as alias
try
set a_list to every file in Afolder as alias list
on error -- only one item present
set a_list to every file in Afolder as alias as list
end try
repeat with i from 1 to number of items in a_list
set a_file to (item i of a_list)
tell application "Cleaner 6.5.1" to Add a_file
end repeat
end tell
tell application "Cleaner 6.5.1" to Setting "web"
tell application "Cleaner 6.5.1" to Start encoding Destination "upload"
to check_cleaner_is_encoding()
delay 3
tell application "Cleaner 6.5.1"
return ProcessingState of GetEncodingStatus is ProcessRunning
end tell
end check_cleaner_is_encoding
Did you mean for me to just add that part of the script, or did you want me to work in the if/then command as well?
I tried it first as you had it “to check_cleaner_is_compressing()” Then I tried it with the word “encoding” because that’s the command you use to start the encode. Thought it might help, but didn’t
I tried is like this as well, but with no luck:
set myFolder to ((path to desktop folder as text) & "Render")
tell application "Cleaner 6.5.1" to activate
tell application "Cleaner 6.5.1" to Clear
tell application "Finder"
set Afolder to (myFolder) as alias
try
set a_list to every file in Afolder as alias list
on error -- only one item present
set a_list to every file in Afolder as alias as list
end try
repeat with i from 1 to number of items in a_list
set a_file to (item i of a_list)
tell application "Cleaner 6.5.1" to Add a_file
end repeat
end tell
tell application "Cleaner 6.5.1" to Setting "web"
tell application "Cleaner 6.5.1" to Start encoding Destination "upload"
on Startencoding()
set isEncoding to check_if_cleaner_is_encoding()
if isEncoding is false then
quit
end if
end Startencoding
to check_cleaner_if_cleaner_is_encoding()
delay 3
tell application "Cleaner 6.5.1"
return ProcessingState of GetEncodingStatus is ProcessRunning
end tell
end check_cleaner_if_cleaner_is_encoding
the handler (to .) is only defined but never called in the script.
I thought you’re looking for a replacement for the EyeTV script
The idea is once it’s done, the program will quit. My script goes on to do other things in other programs, but this is the hang up. I can’t move on unless I know it is completely done encoding.
So I would have to add a line to actually make the command?
Such as:
set myFolder to ((path to desktop folder as text) & "Render")
tell application "Cleaner 6.5.1" to activate
tell application "Cleaner 6.5.1" to Clear
tell application "Finder"
set Afolder to (myFolder) as alias
try
set a_list to every file in Afolder as alias list
on error -- only one item present
set a_list to every file in Afolder as alias as list
end try
repeat with i from 1 to number of items in a_list
set a_file to (item i of a_list)
tell application "Cleaner 6.5.1" to Add a_file
end repeat
end tell
tell application "Cleaner 6.5.1" to Setting "web"
tell application "Cleaner 6.5.1" to Start encoding Destination "upload"
on Startencoding()
set isEncoding to check_if_cleaner_is_encoding()
tell application "Cleaner 6.5.1" to isEncoding
if isEncoding is false then
quit
end if
end Startencoding
to check_cleaner_if_cleaner_is_encoding()
delay 3
tell application "Cleaner 6.5.1"
return ProcessingState of GetEncodingStatus is ProcessRunning
end tell
end check_cleaner_if_cleaner_is_encoding
Sorry, I have no idea how to script Cleaner, but to use a handler like
on myHandler()
-- do something
return somethingElse
end myHandler
you have to call it from somewhere
set theResult to myHandler()
Thanks Stefan. I will keep trudging away. I’ll let you know if I come up with something.
I got rid of the handler, and tried to do an if then command. I’m at least getting a response from script editor this way. I have the following:
set myFolder to ((path to desktop folder as text) & "Render")
tell application "Cleaner 6.5.1" to activate
tell application "Cleaner 6.5.1" to Clear
tell application "Finder"
set Afolder to (myFolder) as alias
try
set a_list to every file in Afolder as alias list
on error -- only one item present
set a_list to every file in Afolder as alias as list
end try
repeat with i from 1 to number of items in a_list
set a_file to (item i of a_list)
tell application "Cleaner 6.5.1" to Add a_file
end repeat
end tell
tell application "Cleaner 6.5.1" to Setting "web"
tell application "Cleaner 6.5.1" to Start encoding Destination "upload"
delay 2
tell application "Cleaner 6.5.1"
return ProcessingState of EncodingStatus
if (ProcessRunning) = false then
delay 3
tell application "Cleaner 6.5.1"
return ProcessingState of EncodingStatus
end tell
else
tell application "Cleaner 6.5.1" to quit
end if
end tell
I get the following error:
Can’t get ProcessingState of EncodingStatus.
I thought the “ProcessingState” was a property of the “EncodingStatus” Like I stated above?
Commands:
- GetEncodingStatus
- BatchItem Status
Properties:
EncodingStatus‚n
properties
ProcessingState (ProcessStopped/ProcessRunning/ProcessPaused/ProcessSleeping, r/o)
NumPasses (integer, r/o)
CurrentPass (integer, r/o)
PercentDone (real, r/o)
first of all: return in a run handler aborts the script!
The command is: GetEncodingStatus