Shutdown script as iCal alarm runs when computer boots again

I’m using 10.7

I created an Applescript to force shutdown at a given time.

It goes like this:
do shell script “shutdown -h now” password “adminpassword” with administrator privileges

When I boot the computer again, the script runs again, immediately shutting down the computer before I can even do anything. :confused:

I’ve tried using TinkerTool to disable the resume feature on iCal, iCal Helper and Finder, but that doesn’t help.

Any ideas how to disable resume on this applescript? Is the fact that it’s resuming even the problem?

Thanks in advance for any help!

Hi tenember,

This seems to work well:

tell application "System Events" to shut down

gl,
kel

Model: MBP
AppleScript: AS 2.2.4
Browser: Safari 536.28.10
Operating System: Mac OS X (10.8)

You could try starting up the computer (or logging in) in safe mode. Hopefully that would prevent the script from being executed immediately and give you time to locate and zap it and to cancel the alarm in iCal. Then restart again in the normal way.

If you go to the Energy Saver pane in System Preferences and click the “Schedule.” button, you can safely set startup and shutdown times there.

Yea! Thanks very much kel1. It’s no longer running at startup.

Thank you for the good advice Nigel. I previously learned how to escape the loop, using the method you describe.
As for the energy saver panel, I’m aware of that too, but need to give different shut down times for each day, hence the iCal method, which now that I’ve just about mastered it with kel1’s help, works quite well.

WAIT, it doesn’t work. I just experienced the same thing. Had to login to different user and switch.

I think I remember this one now. You need to quit all visible processes first. I hope Nigel didn’t already write about this.

set my_name to my name
tell application "System Events"
	set visible of every process to true
	delay 0.5
	set proc_list to (name of every process whose visible is true and name is not "Finder" and name is not my_name)
end tell
repeat with this_proc in proc_list
	tell application this_proc to quit
end repeat
tell application "System Events" to shut down

Needs testing.

gl,
kel

That didn’t work. This seems to be working. Added quitting the Finder:

set my_name to my name
tell application "System Events"
	set visible of every process to true
	delay 0.5
	set proc_list to (name of every process whose visible is true and name is not my_name)
end tell
repeat with this_proc in proc_list
	tell application this_proc to quit
end repeat
tell application "System Events" to shut down

Hope this works. I hate shutting down the computer.

gl,
kel

That didn’t work either. :frowning:

I give up.

Oops. I was testing the wrong script. All hope is not lost.

Yeah, this script seems to be working:

set my_name to my name
tell application "System Events"
	set visible of every process to true
	delay 0.5
	set proc_list to (name of every process whose visible is true and name is not my_name)
end tell
repeat with this_proc in proc_list
	tell application this_proc to quit
end repeat
tell application "System Events" to shut down

I think it’s the same one as above.

gl,
kel

It still doesn’t work. :confused: If I ever find a solution, I’ll be back.

I’m confused - I said that it is working for me. Sorry if it isn’t working for you!

I’m on 10.7, and I’m first force quitting the only app that’s open (VLC). VLC is actually strange in that even if you run an applescript telling it to quit without saving, it stays open until you move the mouse or task switch, and it will actually cancel shutdown until you do that. I worked around that by scripting an apple-tab command one minute later.

So, the scripts run from iCal, one minute apart, and the order is:

Script 1:
tell application “VLC” to quit saving no

Script 2:
tell application “System Events”
delay 0.5
key down command
keystroke tab
delay 10
key up command
end tell

Script 3:
tell application “System Events” to shut down

Hi tenember,

I’m trying to get it to work out of Calendar as a script application. This might be the solution.

tell application "System Events"
	ignoring application responses
		shut down
	end ignoring
end tell

It worked twice, not running after login.

gl,

Model: MBP
AppleScript: AS 2.2.4
Browser: Safari 536.28.10
Operating System: Mac OS X (10.8)