• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Display dialog and select button after so long - Final Code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Display dialog and select button after so long - Final Code


  • Subject: Re: Display dialog and select button after so long - Final Code
  • From: "Ball, Dan" <email@hidden>
  • Date: Thu, 25 Aug 2011 17:39:43 -0400
  • Acceptlanguage: en-US
  • Thread-topic: Display dialog and select button after so long - Final Code

Here is the final code if anyone else wants it....probably not the best
written scripts, but they work!  Must have Lion and turn on Enable access
for assistive devices in Universal Access System Pref pane.

Basically what it does when you run it, it gives 3 options. Restart,
Shutdown, or Cancel.  After 15 seconds it will automatically display the
shutdown window, uncheck the box in Lion to "Reopen windows when logging
back in" and then shutdown.  If you choose the restart or shutdown button
it will uncheck the box and do what the button says.

As far as I know Lion doesn't have a way to disable that checkbox, I put
in an ER to have it unchecked by default, but nothing so far.


Also posted another one with a logoff option with it defaulting to logoff.


Thanks,

Dan


----------SCRIPT ONE----------

tell application "Finder" to activate
tell application "System Events"
	tell process "Finder"
		set dialogResult to (display dialog "Please select your option Quickly!"
& "
Will shutdown in 15 seconds!" buttons {"Restart", "Shutdown", "Cancel"}
default button 2 with icon 0 giving up after 15)
		if gave up of dialogResult then
			my shutdownscript("ShutdownScript")
		else
			set the user_choice to the button returned of dialogResult
			if the user_choice is "Restart" then
				my restartscript("RestartScript")
				return false
			else if the user_choice is "Shutdown" then
				my shutdownscript("ShutdownScript")
				return false
			else if the user_choice is "Cancel" then
				return false
			end if
		end if
	end tell
end tell


-- Restart button

on restartscript(this_anchor)
	tell application "Finder" to activate
	tell application "System Events"
		tell process "Finder"
			click menu item "RestartŠ" of menu 1 of menu bar item "Apple" of menu
bar 1
		end tell
	end tell
	tell application "System Events"
		tell process "loginwindow"
			activate
			click checkbox 1 of window 1
			click button "Restart" of window 1
		end tell
	end tell
end restartscript

-- Shutdown Button

on shutdownscript(this_anchor)
	tell application "Finder" to activate
	tell application "System Events"
		tell process "Finder"
			click menu item "Shut DownŠ" of menu 1 of menu bar item "Apple" of menu
bar 1
		end tell
	end tell
	delay 0.2
	tell application "System Events"
		tell process "loginwindow"
			activate
			click checkbox 1 of window 1
			click button "Shut Down" of window 1
		end tell
	end tell
end shutdownscript

-- Script created by Daniel Ball with some code from Victor Andreoni from
www.gizmoblurb.com










--------------SCRIPT TWO----------------

tell application "Finder" to activate
tell application "System Events"
	tell process "Finder"
		set dialogResult to (display dialog "Please select your option Quickly!"
& "
Will shutdown in 15 seconds!" buttons {"Logoff", "Restart", "Shutdown"}
default button 1 with icon 0 giving up after 15)
		if gave up of dialogResult then
			my logoffscript("LogoffScript")
		else
			set the user_choice to the button returned of the dialogResult
			if the user_choice is "Logoff" then
				my logoffscript("LogoffScript")
				return false
			else if the user_choice is "Restart" then
				my restartscript("RestartScript")
				return false
			else if the user_choice is "Shutdown" then
				my shutdownscript("ShutdownScript")
				return false
			end if
		end if
	end tell
end tell

-- Logoff button

on logoffscript(this_anchor)
	tell application "System Events"
		log out
	end tell
	tell application "loginwindow"
		activate
		tell application "System Events"
			tell process "loginwindow"
				click checkbox 1 of window 1
			end tell
		end tell
		tell application "System Events"
			tell process "loginwindow"
				click button 1 of window 1
			end tell
		end tell
	end tell
end logoffscript

-- Restart button

on restartscript(this_anchor)
	tell application "Finder" to activate
	tell application "System Events"
		tell process "Finder"
			click menu item "RestartŠ" of menu 1 of menu bar item "Apple" of menu
bar 1
		end tell
	end tell
	tell application "System Events"
		tell process "loginwindow"
			activate
			click checkbox 1 of window 1
			click button "Restart" of window 1
		end tell
	end tell
end restartscript

-- Shutdown button

on shutdownscript(this_anchor)
	tell application "Finder" to activate
	tell application "System Events"
		tell process "Finder"
			click menu item "Shut DownŠ" of menu 1 of menu bar item "Apple" of menu
bar 1
		end tell
	end tell
	tell application "System Events"
		tell process "loginwindow"
			activate
			click checkbox 1 of window 1
			click button "Shut Down" of window 1
		end tell
	end tell
end shutdownscript

-- Script created by Daniel Ball with some code from Victor Andreoni from
www.gizmoblurb.com

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Display dialog and select button after so long - Final Code
      • From: Luther Fuller <email@hidden>
References: 
 >Re: Display dialog and select button after so long (From: "Ball, Dan" <email@hidden>)

  • Prev by Date: Re: Display dialog and select button after so long
  • Next by Date: Re: Display dialog and select button after so long - Final Code
  • Previous by thread: Re: Display dialog and select button after so long
  • Next by thread: Re: Display dialog and select button after so long - Final Code
  • Index(es):
    • Date
    • Thread