Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

futsoulja

macrumors newbie
Original poster
Aug 8, 2009
2
0
This is my first post to macrumors and I was hoping to find some help. I am new to applescript and am trying to have an applescript triggered by the low battery notification on a macbook.

The one that says "You are running on reserve power"

Here is the script that I have so far.

Code:
tell application "Safari"
	set cWindow to first item of windows
	set ctIndex to index of current tab of cWindow
	repeat ctIndex - 1 times
		close first item of tabs of cWindow
	end repeat
end tell

tell application "Safari"
	set cWindow to first item of windows
	set ctIndex to index of current tab of cWindow
	repeat while (count of tabs of cWindow) > ctIndex
		close last item of tabs of cWindow
	end repeat
end tell


tell application "Safari" to quit

tell application "Finder" to shut down

I had a problem with safari tabs being open when running this script, preventing the shutdown from happening, so I included the first part to close the tabs. I'm sure there is a better way to do that.

Is there a way to trigger this script to run when the low battery notification pops up? Thanks ahead of time to anyone who can help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.