Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
# Quick and dirty applescript to determine batter life under very light load. This script just navigates Safari to a
# page every 10 seconds to simulate web browsing.
# You'll need to change the file output path (in the log method) for your machine.
# The test:
# * a freshly charged and calibrated battery
# * dim brightness to 50%
# * turn off bluetooth
# * set display to never go to sleep
# * turn screensaver off
# * Use http:// to set graphics card to intel only
# * set itunes to play local music at a low volume through headphones only
set urls to getSiteList()
# open a tab in safari
tell application "Safari"
open "about:blank"
end tell
set startTime to current date
log {" -------------- starting", startTime}
# repeat until mac goes to sleep
tell application "Safari"
set n to random number from 1 to (count urls)
set myUrl to "http://" & (item n of urls)
set URL of document 1 to myUrl
delay 10
end tell
# record the time and elapsed seconds
log {"running ... ", startTime}
end repeat
on log {msg, startTime}
set now to current date
set elapsed to now - startTime
set msg to (now as string) & " (" & (elapsed as string) & " sec): " & msg
set fileRef to open for access ("/Users/andre/Desktop/battery_test.txt" as string) with write permission
write msg & "
" to fileRef starting at eof
close access fileRef
end log
# list of sites -- taken from Alexa top sites
on getSiteList()
return every paragraph of ""
end getSiteList
# not used
#on readFileToArray(unixPath)
# set tmp to (do shell script "cat '" & unixPath & "'")
# return every paragraph of tmp
#end readFileToArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.