Jump to content

Shut down or restart your Computer


Recommended Posts

Hello, 

 

I'm a freshman, but i made a small workflow, especially an applescript which allows you to shut down or restart your computer.

Thats not really a big thing, but the script quits all apps before shutting down so that no app is reopened after restart.

Additional the script ejects one or all mounted HDs. I need this small section in the script, because my mac wouldn't shut down if one special external HD is mounted while shutting down.

 

I made three workflows/scripts, the first one only shuts down, the second makes a restart and the third combines both, all with the additional functions I mentioned at the beginning.

 

I hope you can use it  ;)

 

Only the shut down-script:

display dialog "Your mac will shut down in 5 seconds!" with title "shut down" giving up after 5

tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder" and name is not "Alfred"
repeat with closeall in quitapps
quit application closeall
end repeat

	tell application "Finder"
		if (exists disk "Bildmaterial") then
			tell application "Finder"
				eject disk "Bildmaterial"
			end tell
		else
			shut down
		end if
		shut down
	end tell

-> download the workflow

 

 

Only the restart-script:

display dialog "Your mac will restart in 5 seconds!" with title "restart" giving up after 5

tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder" and name is not "Alfred"
repeat with closeall in quitapps
quit application closeall
end repeat

tell application "Finder"
	if (exists disk "Bildmaterial") then
		tell application "Finder"
			eject disk "Bildmaterial"
		end tell
	else
		restart
	end if
	restart
end tell

-> download the workflow

 

 

One for all - shut down/restart:

display dialog "Your mac will shut down in 5 seconds!" with title "shut down" buttons {"cancel", "restart", "shut down"} default button 3 giving up after 5

set button_pressed to the button returned of the result

tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder" and name is not "Alfred"
repeat with closeall in quitapps
	quit application closeall
end repeat

if button_pressed is "shut down" then
	tell application "Finder"
		if (exists disk "Bildmaterial") then
			tell application "Finder"
				eject disk "Bildmaterial"
			end tell
		else
			shut down
		end if
		shut down
	end tell
else if button_pressed is "restart" then
	
	tell application "Finder"
		if (exists disk "Bildmaterial") then
			tell application "Finder"
				eject disk "Bildmaterial"
			end tell
		else
			restart
		end if
		restart
	end tell
end if

tell application "Finder"
	if (exists disk "Bildmaterial") then
		tell application "Finder"
			eject disk "Bildmaterial"
		end tell
	else
		shut down
	end if
	shut down
end tell

-> download the complete workflow

Edited by freakmac5
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...