Restart computer at end of script app

I have dabbled trying to accomplish this but have not spent a lot of time researching how to do it. I have an AppleScript app that I run everyday and once done I need to quit all running apps and restart the computer. The issue is I can quit all the apps and restart the computer but when it restarts the AppleScript app comes up as running. How can I quit the AppleScript app to insure it will not re-execute on startup?

How about this?

do shell script "shutdown -r now" with administrator privileges

1 Like

Thanks maro, I know how to do the restart. The issue I have when the computer completes the reboot the app shows up as still running. I need to be able to restart and quit the app so it is not back up and running at reboot time.

Are you saying the app is running after you reboot?

If yes, then either it’s a startup item or the option “Launch apps that are running” (or smth to the effect of that) is selected in the shutdown dialog at the time you restart the computer. Other than that it’s hard to figure out why the app is running.

Model: MacBook Pro
AppleScript: 2.2.1
Browser: Safari 534.57.7
Operating System: macOS 10.7

Try this:

tell application "System Events" to restart with state saving preference

…or try:

tell application "Finder" to restart

FWIW, the AppleScript dictionary entry for the Finder “restart” command shows it as being part of the Legacy Suite with the comment:

Also, the System Events restart command has the state-saving preference, and I think that’s needed to do what the OP wants (at least in my testing). This preference is defined as:

It appears that the state-saving preference refers to the option on the restart menu to:

This one worked for me after my system hung (no menu bar or desktop icons, just wallpaper visible) during a restart from the Apple menu when neither the system events or Finder commands worked (possibly because both Finder and system events had already been stopped). I just had to authorize a prompt from osascript with my admin password. Thanks!