Re: Panther bug: 'missing value' for modification date??
Re: Panther bug: 'missing value' for modification date??
- Subject: Re: Panther bug: 'missing value' for modification date??
- From: Harald E Brandt <email@hidden>
- Date: Thu, 19 Feb 2004 21:56:14 +0100
+--> Christopher Nebel wrote 04-02-19:
There's no real workaround aside from trying until you get a real answer.
+-
... tears dripping from my cheek... all my nightly scripts and other
mirroring will hate the Panther cat...! I thought I gave them a
present...
+--> Graff wrote 04-02-19:
If all else fails you should be able to use a shell script to substitute:
-----------------
set theFile to choose file
set posixFile to quoted form of POSIX path of theFile
set theScript to "ls -l -T " & posixFile & " | awk '{ print $7 \" \"
$6 \" \" $9 \" \" $8 }'"
set modTime to date (do shell script theScript)
+-
For single items, this is of course a disaster (from a timing
perspective). But for a list of e.g 8 items, it can actually be
turned into something that is sligthtly faster than 'info for' (but
slower than Finder). (And as far as I can tell, it should work for
all locales.) An example:
set fList to {"HD:Library:Fonts:Arial", "HD:Library:Fonts:Arial
Black", "HD:Library:Fonts:Arial Narrow", "HD:Library:Fonts:Arial
Rounded Bold", "HD:Library:Fonts:Georgia",
"HD:Library:Fonts:Verdana", "HD:Library:Fonts:Trebuchet MS",
"HD:Library:Fonts:Webdings"}
----- DO SHELL SCRIPT VERSION -----
set modDate to {}
set t0 to GetMilliSec --just to time it
set fUlist to ""
repeat with x in fList
set fUlist to fUlist & " " & quoted form of POSIX path of x
end repeat
set theScript to "ls -l -T " & fUlist & " | awk '{ print $7 \" \" $6
\" \" $9 \" \" $8 }'" --US-month day, year, time
set res to (do shell script theScript)
repeat with x in paragraphs of res
set end of modDate to date x
end repeat
((GetMilliSec) - t0) / (length of fList)
(result as string) & " ms" & return & modDate
------ END
The result is about 5.5 ms measured by running a script that has been
loaded from file, but about 7.3 ms if just 'run script file'.
The 'info for' version is about 6.5 ms (and for some reason it does
not seem to care so much if it is 'run script file' or running a
script that has been loaded from file?).
The Finder version with a loop would be like this:
----- FINDER VERSION -----
tell application "Finder" to set n to kind of file (item 1 of fList)
--the above line is just to "exercise" the script so we get rid of
the initial "extra charge" for a Finder call
set t0 to GetMilliSec
repeat with x in fList
repeat
tell application "Finder" to set modDate to
modification date of file x
if result is not missing value then exit repeat
end repeat
end repeat
((GetMilliSec) - t0) / (length of fList)
(result as string) & " ms" & return & modDate
----- END
The result is about 4.5 ms if executed as 'run script file'.
(However, if executed by running a script that has been loaded from
file, we get as unpredictable results as when run directly in Script
Editor - about 4 - 18 ms, so I think this is a bad method of
measuring scripts with application calls.)
The bottom line, considering Chris' statement about repeating until
success, the Finder loop is the best one.
The only exception would be a folder with lots of items (or a large
list), where the shell version could be faster.
Can you do better?
Best Regards,
______heb__________________________
Harald E Brandt
http://bragit.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.