Measuring bandwidth via Safari

I’m writing a little app here at work to measure (among other things) bandwidth for file copies over our new wireless network.

I have a request to measure internet bandwidth as well as file copy bandwidth. Here’s the code I have for the latter:

set theDateStart to (current date)
	set theTimeStart to (time string of theDateStart)
	set theTimeStartSec to time of theDateStart
	tell application "Finder"
		with timeout of 3000 seconds
			move file "server:file" to theServerCopyPath
		end timeout
	end tell
	set theTimestop to (current date)
	set theTimeStopSec to time of theTimestop
	set x to theTimeStopSec - theTimeStartSec as text
	display dialog theTimeStart & "--" & theTimestop & " ... therefore, the total time is " & x & " seconds"

Anyone know of a way to set this up to do the same in Safari?

When I take this code and plug Safari into it, I’m told it takes “0” seconds – because once Safari goes to the site I list, AppleScript (in this case, Xcode) assumes the whole thing is done, and returns theTimeStart to be the same as theTimeStop.

There has to be an easier way …

Scripting support in Safari is lacking to say the least, but there is another way. There’s a component of OS X called “URL Access Scripting” which allows for scripting of uploading and downloading files. It’s its own application. Also, there’s no need to convert the “current date” into seconds. If you set t1 to the current date, do something, set t2 to the current date, and subtract t2-t1, it will return the number of seconds difference automatically. Something like:

set theDateStart to (current date)

tell application "URL Access Scripting"
	with timeout of 3000 seconds
		download "" to "save:path:for:textfile.txt"
	end timeout
end tell

set theTimestop to (current date)
set theSecs to (theTimestop - theDateStart)
display dialog theSecs as string & " seconds"

shold work. Obviously you’ll have to change the address you want to download from. Also, when telling the script where to download the file to, you must specify a filename, if you just specify a folder, it will error. The file name you download to doesn’t have to be the same as the name of the file your downloading.

Hope this helps.

“Can’t make some data into the expected type” … and it highlights the “download” section of the script.

NEVERMIND … I put a goofy argument at the end of the script (

progress yes

instead of

progress true


Proving once again the wise words of my manager: Every day I feel like I have to learn AppleScript all over again. :shock:

So it’s working then? I had originally included the “with progress” statement but couldn’t get it to do anything (e.g., no progress indicator) so I took it out. Does it do anything for you?

no, does nothing for me. but yes, the script works as advertised.