Guys. I’ve had a nose around this great scripting community to try and find this, apologies if I have overlooked a previous post.
I’m looking to load a webpage in safari, say www.cnn.com and record the data/time the request was made. Then record the date/time the page was fully completed and give the duration in seconds/milliseconds in a log file? Thanks, Martin
Model: iMac G5 and Intel based, MacMini G4
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
try this (it requires the Scripting Addition GetMilliSec)
property httpURL : "http://www.cnn.com"
set logfile to ((path to desktop as Unicode text) & "logfile.txt")
set t to GetMilliSec
tell application "Safari" to open location httpURL
if page_loaded(200) is false then error number -128
set t1 to ((GetMilliSec) - t) / 1000
write_to_disk from (((current date) as string) & ": " & httpURL & " opened in " & t1 & " seconds" & return) into logfile
on write_to_disk from theData into targetFile
set ff to open for access file targetFile with write permission
write theData to ff starting at eof
close access ff
repeat with i from 1 to the timeout_value
tell application "Safari"
else if i is the timeout_value then
Stefan, I’m sure this script is more than suitable but I’m having trouble with the Script Addition “getmillisec” and getting it to be recgnised by the script.
Is there any chance you could give me a step by step on how to install the additions onto my OS 10.4 system.
I have the unstuffed “GetMilliSecOSAX1.0.1” on my desktop.
Currently, as I’m sure you’d expect, the error the script is returning is : “The variable GetMilliSec is not defined”
Your help is appreciated. Martin (it’s a big old lurning curv man)
In the GetMilliSecOSAX folder there are three Scripting Addition files, we need GetMilliSec.osax
¢ Quit Script Editor
¢ Put GetMilliSec.osax into /Library/ScriptingAdditions/
¢ Restart Script Editor
OK Stefan, done as instructed, the script compiles ok but I still get the AppleScript Error “The variable GetMilliSec is not defined” when I run it. The variable “getmillisec” is highlighted alongside the line of code
set t to GetMilliSec
Do you have any suggestions Stefan as to what might be causing this other than how I have copied the getmillisec.OSAX file into Library/ScriptingAdditions?
I’ve also tried putting it into a few other locations such as root\Library (and then created a “ScriptingAdditions” folder, as I did for root\Users\username\Library.
The only folder that had an existing “ScriptingAdditions” folder was root\System\Library. I’ve copied the file into 3 locations now and still the script error persists. Sorry to go on… Thanks again, Martin
this is strange. It doesn’t matter, which Scripting Additions’ folder you use to put the file in.
I prefer /Library/Scripting Additions/, in this folder the OSAX is available for all users.
Normally the Scripting Addition will be recognized, when Script Editor will be quitted and restarted.
I guess, the problem is, you have an Intel Mac and the OSAX is a PPC extension.
Maybe other members of this board have some experience with a PPC OSAX on a Intel machine.
A different approach is to use AppleScript’s time, but the smallest unit is seconds
set t to GetMilliSec with set t to (current date) and
set t1 to ((GetMilliSec) - t) / 1000 with set t1 to (current date) - t
Without GetMilliSec, there’s always this Python script (which seems to have an overhead of about 200 ms for a call):
I think it’s the time from the unix epoch.
set t1 to do shell script "python -c 'import time; print time.time();'"