Restart from clone

Success!

I still need to polish the version that simply switches between two volumes, but the “universal” version is finished. I considered trying to fetch the admin password, but decided against it. Is that even possible? Anyway, here it is, comments and all:


--with thanks to Jacques, walter, and Dominik


--Set initial variables.
set bootList to {}
set myPass to "admin_password" --Put you password within the quotation marks to prevent a dialog requesting it.

--Get a list of mounted bootable volumes, save it as a variable.
tell application "Finder"
	repeat with possibleBoots in (get disks whose startup is false)
		if exists folder "System:Library:CoreServices" in possibleBoots then set end of bootList to name of possibleBoots
	end repeat
end tell

--Warn the user if no other bootable volumes are mounted.
if bootList is {} then
	beep
	display dialog "No other bootable volumes detected. Mount a volume and try again" buttons {"Okay"} with icon stop default button 1
	
else
	--Set the subroutine to restart the computer from the chosen volume
	
	
	--Convert the list of bootable volumes to dialog buttons with a default cancel button -  for safety and convenience. 
	set bootButtons to bootList & "Cancel"
	
	if (count of bootButtons) ≤ 3 then
		set bootVolume to button returned of (display dialog "Boot from which volume?" buttons bootButtons default button 3)
		myChangeBoot(bootVolume, myPass)
	else
		
		--There is a three button maximum for dialogs; this is called if the limit is exceeded 
		set bootVolume to (choose from list bootList)
		myChangeBoot(bootVolume, myPass)
	end if
end if

--Restart from the chosen volume.
on myChangeBoot(bootVolume, myPass)
	
	set rebootCommand to "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now"
	tell application "Finder" to exists disk bootVolume
	if result then
		do shell script rebootCommand password myPass with administrator privileges
	end if
end myChangeBoot



Could this be improved? Is it useful enough to share? Freely, of course.

I think I’ll create a nifty icon for it after I finish the other version.

j

Hi Jacque.

Maybe working into the wee hours (again - but this is when the kids are quiet) is causing me to miss the obvious, but I thought this took care of that problem. It did in all my tests:

if bootList is {} then
   beep
   display dialog "No other bootable volumes detected. Mount a volume and try again" buttons {"Okay"} with icon stop default button 1
   

When I ran tests (both in Script Editor and from the saved application) with my external drive disconnected, that dialog popped up as expected. I also changed this:

if (count of bootButtons) ≤ 3 then

to this:

if (count of bootButtons) ≤ 2 then

to force a (choose list) to test, and below the list were two buttons, “Cancel” and “Okay,” and clicking “Cancel” (intead of selecting a volume an clicking “Okay”) quit the script (and saved app.) If the external drive was diconnected then the “No other bootable volumes detected. Mount a volume and try again” dialog stopped the process.

As an added measure, I also did this:

set bootVolume to button returned of (display dialog "Boot from which volume?" buttons bootButtons default button 3)

so that if there were three bootable volumes, the script could be stopped - I stared stupidly at my screen for several minutes (I didn’t know what process to kill with Activity Monitor) during that test; I finally remembered that I hadn’t put my password in the script, so I canceled in that dialog.

You know a heckuva lot more than I do, though.

My wife woke up to use the bathroom, and was pretty annoyed to find me hunched over the keyboard. I’ll check back at a decent hour.

Thanks for the help

j

hi J,

i like what you’ve done. good script. if you still wanted to include a trip to the system preferences on error, you could do it like this:


--Warn the user if no other bootable volumes are mounted.
if bootList is {} then
	beep
	set myReturn to display dialog "No other bootable volumes detected. Mount a volume and try again.  Use \"Startup Disk\" to open your System Preferences." buttons {"Okay", "Startup Disk"} with icon stop default button 1
	set myButton to button returned of myReturn
	if myButton is "Startup Disk" then
		tell application "System Preferences"
			activate
			set current pane to pane "com.apple.preference.startupdisk"
		end tell
	end if
else

I really like Jacques’ version as given in post #22 to this thread, with two comments:

  1. The shell script restart is ‘brutal’ - nothing saved so a reminder is required.
  2. In the case that the bootlist < 3 (only one option), the dialog doesn’t have a “Cancel” button, so you’re committed even if it occurs to you that you’ve left something unsaved.

The minor modifications below prevent me from stomping on my own toes.

set bootList to {}
set myPass to "admin_password"

tell application "Finder"
	repeat with this_disk in (get disks whose startup is false)
		if exists folder "System:Library:CoreServices" in this_disk then set end of bootList to name of this_disk
	end repeat
end tell

set warned to button returned of (display dialog "No open documents will be saved!" & return & return & "Do you wish to proceed?" buttons {"Cancel", "Proceed"} default button 1 with icon 2)

if bootList is not {} then
	if (count bootList) ≤ 3 then
		set bootVolume to button returned of (display dialog "Boot from which volume?" buttons {"Cancel", bootList})
	else
		set bootVolume to (choose from list bootList) as string
		if bootVolume is "false" then return -- user canceled then quit the script
	end if
	do shell script "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now" password myPass with administrator privileges
else
	beep
	display dialog "No bootable volumes detected. Mount a volume and try again" buttons {"Okay"} with icon stop default button 1
end if

As an aside, I have a USB driven powerbar that will turn my firewire external on from an AppleScript if it happens to be off, so this is a very nice way to check that a clone is as it should be. Thanks.

Thanks, waltr, high praise indeed.

I almost did something much like that, but it seemed redundant. Is there a scenario where that would be a useful feature?

I’ll planned on working it into the other version - the one to toggle between two volumes saved as variables - because it seems obviously helpful there. I’ll post that when I finish.

Sadly (I thought I was finished) I found a problem - my script returns errors if a bootable disk (Install, DiskWarrior, etc.) is in my disk drive. If there are no additional bootable voumes, I get “Specified button does not exist” and:


--display dialog "Boot from which volume?" buttons bootButtons default button 3 is highlighted in Script Editor, but not the parentheses enclosing it.
	if (count of bootButtons) ≤ 3 then
		set bootVolume to button returned of (display dialog "Boot from which volume?" buttons bootButtons default button 3)
		myChangeBoot(bootVolume, myPass)
	else

If my external drive is connected, I get the (choose list) but if I select a volume i get “Finder got an error: Can’t make some data into the expected type.” and:


-- the words exists disk bootVolume are highlighted in Script Editor.
 
on myChangeBoot(bootVolume, myPass)
	
	set rebootCommand to "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now"
	tell application "Finder" to exists disk bootVolume
	if result then
		do shell script rebootCommand password myPass with administrator privileges
	end if
end myChangeBoot


If I run just this:

set bootList to {}
set myPass to "admin_password" --Put you password within the quotation marks to prevent a dialog requesting it.

--Get a list of mounted bootable volumes, save it as a variable.
tell application "Finder"
	repeat with possibleBoots in (get disks whose startup is false)
		if exists folder "System:Library:CoreServices" in possibleBoots then set end of bootList to name of possibleBoots
	end repeat
end tell

It returns “Mac OS X Install Disc 1”

As soon as my disk drive is empty, everything is fine. Nonbootable disks in my drive (CDs, software, etc.) cause no problems. I’m stumped.

Any suggestions?

Thanks a million, as usual.

Oh, and I just recieved an e-mail that Adam Bell posted a reply. I’ll go read that.

j

Hi Adam, and thanks for your insight.

I tried to address point 2, but spaced on point 1. Whoopsie.

My version in post #24 deals with the need for a cancel button when ther are fewer than 3 volumes, although
I just noticed that I should change “≤ 3” to “< 3” and maybe that will help with my latest problem (see post #29):

 --Convert the list of bootable volumes to dialog buttons with a default cancel button - for safety and convenience. 
   set bootButtons to bootList & "Cancel"
   
   if (count of bootButtons) ≤ 3 then
       set bootVolume to button returned of (display dialog "Boot from which volume?" buttons bootButtons default button 3)
       myChangeBoot(bootVolume, myPass)
   else

and the choose list has a cancel button, but I neglected to add a save warning that would pop up as a final reminder - even after I had to resort to a screenshot to save changes to a script revision - because I was so absorbed by a different issue that I forgot to go back to the issue of open documents. I need to fix that. Would it be possible to save open documents first, or is that impractical?

I’m still confused by this:

if bootVolume is "false" then return -- user canceled then quit the script

which Jacques reminded me about in post #25. Please see my response in post #26. In short, I thought, after testing, that this solved that because it stops the script before the subroutine to choose a volume and restart, and only bootable volumes get passed along:

--Warn the user if no other bootable volumes are mounted.
if bootList is {} then
   beep
   display dialog "No other bootable volumes detected. Mount a volume and try again" buttons {"Okay"} with icon stop default button 1
   
else

Thanks again. I’ll get back to work.

j

I just saw what was breaking my script, I’ll post back. I didn’t want to waste anybody’s time.

EDITED: I know, this post is itself a waste of time. Sorry.

Hi everybody,

It just dawned on me that my last post:

probably is a waste of time to anybody subscribed to this thread. My apologies. I tend to drone on in person sometimes, too, according to my wife.

As for the script breakage mentioned in post #29, I had to change this:

--Convert the list of bootable volumes to dialog buttons with a default cancel button -  for safety and convenience. 
	set bootButtons to bootList & "Cancel"
	
	if (count of bootButtons) ≤ 3 then
		set bootVolume to button returned of (display dialog "Boot from which volume?" buttons bootButtons default button 3)
		myChangeBoot(bootVolume, myPass)
	else

to this:

--Convert the list of bootable volumes to dialog buttons with a default cancel button -  for safety and convenience. 
	set bootButtons to bootList
	
	if (count of bootButtons) < 3 then
		set bootVolume to button returned of (display dialog "Boot from which volume?" buttons {"Cancel", bootButtons} default button 1)
		myChangeBoot(bootVolume, myPass)
	else

Now to deal with Adam’s suggestions…

if bootList is not {} then
	if (count bootList) < 3 then -- If a "Cancel" button is to be included, there are only two left - a dialog only has 3 buttons.
		set bootVolume to button returned of (display dialog "Boot from which volume?" buttons {"Cancel", bootList})
	else
		set bootVolume to (choose from list bootList) as string -- a list required for more than two + cancel.
		if bootVolume is "false" then return -- user canceled then quit the script -- if the user chooses "Cancel", choose from list returns false.
	end if
	do shell script "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now" password myPass with administrator privileges
else
	beep
	display dialog "No bootable volumes detected. Mount a volume and try again" buttons {"Okay"} with icon stop default button 1
end if

You are relying on “choose from list” to avoid an empty selection or multiple selections which have to be specifically allowed. Note that if nothing is defaulted or chosen the “OK” button is dimmed, so you don’t really need the empty list test. You must either choose something, or cancel.

Thanks Adam, I think I understand.

I can remove this because it is unnecessary:

if bootList is not {} then

and use this:

 if (count bootList) < 3 then
       set bootVolume to button returned of (display dialog "Boot from which volume?" buttons {"Cancel", bootList})
   else
       set bootVolume to (choose from list bootList) as string
       if bootVolume is "false" then return
   end if
   do shell script "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now" password myPass with administrator privileges
else
   beep
   display dialog "No bootable volumes detected. Mount a volume and try again" buttons {"Okay"} with icon stop default button 1
end if

because this line:

if bootVolume is "false" then return

essentially clicks the cancel button when bootList is empty, and the script moves on to here:

else
   beep
   display dialog "No bootable volumes detected. Mount a volume and try again" buttons {"Okay"} with icon stop default button 1
end if

But I did it differently, and the way I wrote it (this is the latest version, still lacking the save warning):

--with thanks to Jacques, walter, Dominik, and Adam Bell


--Set initial variables.
set bootList to {}
set myPass to "admin_password" --Put you password within the quotation marks to prevent a dialog requesting it.

--Get a list of mounted bootable volumes, save it as a variable.
tell application "Finder"
	repeat with possibleBoots in (get disks whose startup is false)
		if exists folder "System:Library:CoreServices" in possibleBoots then set end of bootList to name of possibleBoots
	end repeat
end tell

--Warn the user if no other bootable volumes are mounted.
if bootList is {} then
	beep
	display dialog "No other bootable volumes detected. Mount a volume and try again" buttons {"Okay"} with icon stop default button 1
	
else
	--Set the subroutine to restart the computer from the chosen volume
	
	
	--Convert the list of bootable volumes to dialog buttons with a default cancel button -  for safety and convenience. 
	set bootButtons to bootList
	
	if (count of bootButtons) < 3 then
		set bootVolume to button returned of (display dialog "Boot from which volume?" buttons {"Cancel", bootButtons} default button 1)
		myChangeBoot(bootVolume, myPass)
	else
		
		--There is a three button maximum for dialogs; this is called if the limit is exceeded 
		set bootVolume to (choose from list bootList)
		myChangeBoot(bootVolume, myPass)
	end if
end if

--Restart from the chosen volume.
on myChangeBoot(bootVolume, myPass)
	
	set rebootCommand to "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now"
	tell application "Finder" to exists disk bootVolume
	if result then
		do shell script rebootCommand password myPass with administrator privileges
	end if
end myChangeBoot



is also okay, too, but I organized the script in essentially the same order as that of the dialog boxes because of, um linear noob thinking. But I think it is easy to read and looks nice.

I hope I am up to speed - I felt like I couldn’t find the glasses on top of my head.

Thanks again for taking the time to explain that,

j

Hello all.

I think I might have it, other than some editing for consistency.

My biggest stumbling block was a conflict between this, which returns a one item list:

set bootVolume to (choose from list bootList)

and this, which can’t parse a list:

tell application "Finder" to exists disk bootVolume

It ocurred to me that the exists command was redundant because of this:

tell application "Finder"
	repeat with possibleBoots in (get disks whose startup is false)
		if exists folder "System:Library:CoreServices" in possibleBoots then set end of bootList to name of possibleBoots
	end repeat
end tell

I found two solutions, and each works. The first eliminates the exists command. My script is heavily commented, partly to describe how it is organized, partly to mark pitfalls for future reference. Please excuse the verbosity:



--With thanks to Jacques, walter, Dominik, and Adam Bell.

--EDIT: Comments updated to include corrections from Adam in post #36


-- Substitute your password within quotations for "adminPassword" to prevent a dialog requesting it.
set myPass to "adminPassword"

--This gets a list of mounted bootable volumes and saves it as a variable.
set bootList to {}
tell application "Finder"
	repeat with possibleBoots in (get disks whose startup is false) --Get the mounted, unbooted disks.
		if exists folder "System:Library:CoreServices" in possibleBoots then set end of bootList to name of possibleBoots --Filter out unbootable disks, set bootable disks to bootList.
	end repeat
end tell

--This allows the user to cancel the script if no other bootable volumes are mounted. It is inelegant but easy to read and displays a nicer looking dialog.
if bootList is {} then
	beep --Comment this word if you dislike beeps.
	set stopSpaces to (space & space & space & space & space)
	display dialog "No other bootable volumes detected." & return & stopSpaces & "Mount a volume and try again." buttons {"Okay"} with icon stop default button "Okay"
	
else
	
	--This warns  the user against unsaved changes. For a more traditional dialog, comment the following three lines and uncomment their equivalent below; if you prefer to live dangerously, comment the following three lines and leave their equivalent commented, too.
	
	beep --Comment this word if you dislike beeps
	set theSpaces to (space & space & space & space & space)
	set lastWarnedRespose to button returned of (display dialog return & "Unsaved changes abandon," & return & theSpaces & "ye who continue here." buttons {"Cancel", "Continue"} default button 1 with icon caution)
	--beep
	--set foreSpaces to (space & space & space & space & space & space & space & space)
	--set forewarnedResonse to button returned of (display dialog return & "Unsaved documents will be lost." & return & foreSpaces & "Proceed with caution." buttons {"Cancel", "Continue"} default button 1 with icon 2)
	
	
	--This sets the subroutine that restarts the computer from the chosen volume.
	set bootButtons to bootList -- This converts the list of bootable volumes to dialog buttons. Do not do "Cancel" & bootlist. It breaks the dialog because with "Cancel" first, the combination is text; AppleScript coerces the list bootlist to match the first item in the concatination. If you want the "Cancel" on the left, do {"Cancel"} & bootlist.
	
	if (count of bootButtons) < 3 then --This cannot be ≤3 because a default "Cancel button is going to be added for safety.
		set bootVolume to button returned of (display dialog "Boot from which volume?" buttons (bootButtons & "Cancel") default button "Cancel") --Do not do this - {bootButtons & "Cancel"} - it won't work because it returns a list within a list- bootButtons is {"A", "B"}. Concatinating "Cancel" coerces " it to {Cancel}, so adding it to the bootButtons list results in {"A", "B", "Cancel"}. If you enclose the concatination in braces you get {"A", "B", {"Cancel"}}.

		myChangeBoot(bootVolume, myPass)
	else
		
		--There is a three button maximum for dialogs; this runs if that limit is exceeded. 
		set bootVolume to (choose from list bootList)
		myChangeBoot(bootVolume, myPass)
	end if
end if


--Restart from the chosen volume.
on myChangeBoot(bootVolume, myPass)
	
	set rebootCommand to "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now"
	do shell script rebootCommand password myPass with administrator privileges
end myChangeBoot

--Phew!



My alternate ending keeps the exists command in case it turns out that it’s better to do so:

else
		
		--There is a three button maximum for dialogs; this is runs if that limit is exceeded. 
		set bootVolume to (choose from list bootList) --The return of this is a list, which breaks the exists command
		set theChoice to bootVolume as string --This converts the list to a string, necessary for the exists command. Another solution is to disable the exists command.
		myChangeBoot(theChoice, myPass)
	end if
end if


--Restart from the chosen volume.
on myChangeBoot(bootVolume, myPass)
	
	set rebootCommand to "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now"
	tell application "Finder" to exists disk bootVolume
	if the result is true then
		do shell script rebootCommand password myPass with administrator privileges
	end if
end myChangeBoot


So how did I do?

I’d like to return to the version that toggles between two volumes, but it is now - egad! - 4 a.m.

Thanks to everybody.

j

Looks good.

Minor comment: Put the definition of theSpaces before the if-then-else block, i.e. right after set myPass - you only need to define it once. When I’m fiddling with formatting like that, I usually use this which makes tuning just a matter of changing the number n in makeSpace(5):

to makeSpace(n)
	set sp to ""
	repeat n times
		set sp to sp & space
	end repeat
	return sp
end makeSpace

Later, you note: This converts the list of bootable volumes to dialog buttons. Do not do “Cancel” & bootlist. It breaks the dialog.

This breaks the dialog because with “Cancel” first, the combination is text; AppleScript coerces the list bootlist to match the first item in the concatination. If you want the “Cancel” on the left, then {“Cancel”} & bootlist does it.

set bl to {"A", "B"}
display dialog "Test" buttons {"Cancel"} & bl

Further along, you say: Do not do this - {bootButtons & “Cancel”} - it won’t work because it returns a list within a list.

As expected. bootButtons is {“A”, “B”}. Concatinating “Cancel” first coerces “Cancel” to {Cancel}, then adds it to the bootButtons list → {“A”, “B”, “Cancel”}. If you enclose the concatination in braces you get {{“A”, “B”, “Cancel”}}.

Finally, you say:There is a three button maximum for dialogs; this is called if that limit is exceeded.

It isn’t “called”. Because the earlier tests failed, this runs.

All told, you’ve got it.

Hi Adam.

Thanks for the suggestions, especially the one to post the script. (EDIT: :rolleyes: Oh yeah, that’s your signature. - on every post.) I feel almost ready to do that.

I will edit my posted script and comments ASAP to include your corrections; I tried to use the right terminology, and it helps me to look back and see what, why, and how to describe what I did.

I’m working on a subroutine to save open documents. I had this as a test:

tell application "TextEdit" to quit saving yes

and if I set up up repeat loop, the user would have to deal individually with some save dialogs, but some documents might have unwanted changes saved. So I decided this is a better direction:

tell application "TextEdit" to quit

because a causes a “review chages” dialog - but my concern is how to set up a loop without quitting necessary processes. Should I loop processes whose frontmost is true? Am I just getting carried away here? I am new to this, but am beginning to feel like a scriptoholic - I’m supposed to be remodeling the bathroom (stay at home Dads with powertools have bottomless job jars) but I am at the computer in my pajamas at lunchtime.

Thanks for your help (and patience)

j

You might try:

tell application "System Events" to set p to name of every process whose visible is true

This returns a list of all YOUR processes that are running and not hidden. You can cycle through that and quit them, but will miss any hidden processes.

This turns them visible first:

tell application "System Events"
	tell every process to set its visible to true
	set p to every process whose visible is true
end tell

– p is a list of all your running processes. [Not extensively tested, though]

repeat with anApp in p
	tell application anApp to quit
end repeat

Thanks, Adam.

Visible. Should have been obvious.

Because of the way I work, I was thinking that what’s hidden is best left alone, but I want this to be as widely applicable as possible. I need to experiment - I’ll give it a try in a bit. I’m risking a stay in the doghouse just by reponding to your post.

j

Been there too. Scripting kinda grabs you, doesn’t it.

I’m making progress.

After fiddling, I got this to work:


--Save as an "Save and Quit.app" (Script Editor can't quit during a running script.)

tell application "Finder" to close every window --Otherwise windows hide the save dialog.

tell application "System Events"
	tell every process to set its visible to true
	--Must be "name of every process" to avoid return of "Can't get application (application process \"Application_Name\" of application \"System Events\") in the next step.
	set quitApp to name of every process whose visible is true and name is not "Finder" and name is not "Save and Quit" --Trying to quit these two will break the script. Change "Save and Quit" to the name of whichever application incorporates this scriptlet.
end tell

repeat with anApp in quitApp
	tell application anApp to quit
end repeat

I think it’s ready to work into the main script.

j

Good catch not to quit the application doing the quitting - as I said, I had not extensively tested the quitting part - I just assured myself that a visible could be quit in this way.

My Finder will quit. It’s System Events that’s doing the quitting, I think.

Hello Adam.

I didn’t so much catch it as the reverse. TinkerTool - http://www.bresink.com/osx/ - gives me the “quit Finder” option. I unchecked it for unrelated reasons or I might have missed that potential conflict, too. I also have TinkerTool System.

As for the script, it still needs a bit of beautifying, but now includes the option to review open documents - however that requires exiting the script. Is it possible to make it idle until during this:


tell application "Finder" to close every window
		tell application "System Events"
			tell every process to set its visible to true
			
			set quitApp to name of every process whose visible is true and name is not "Finder" and name is not "uBoot"
		end tell
		
		repeat with anApp in quitApp
			tell application anApp to quit
		end repeat

and then move on to:


myChangeBoot(bootVolume, myPass)

If that’s not possible, I’ll put some lipstick on this pig and be done. Then I can finish my original idea for toggling between my HD and its clone.

Here is the full script, with most comments removed for brevity:



--uBoot (working name)
--With thanks to Jacques, walter, Dominik, and Adam Bell.
--SAVE AS AN APPLICATION.

-- Substitute your password within quotations for "adminPassword" to prevent a dialog requesting it.
set myPass to "adminPassword"

--This gets a list of mounted bootable volumes and saves it as a variable.
set bootList to {}
tell application "Finder"
	repeat with possibleBoots in (get disks whose startup is false)
		if exists folder "System:Library:CoreServices" in possibleBoots then set end of bootList to name of possibleBoots
	end repeat
end tell

--This allows the user to cancel the script if no other bootable volumes are mounted. It is inelegant but easy to read and displays a nicer looking dialog.
if bootList is {} then
	beep
	set preStopSpaces to ""
	repeat 5 times
		set preStopSpaces to preStopSpaces & space
	end repeat
	set stopSpaces to preStopSpaces
	beep
	set checkVolumesResponse to display dialog "No other bootable volumes detected." & return & stopSpaces & "Mount a volume and try again." buttons {"Open System Preferences", "Okay"} with icon stop default button "Okay"
	set checkVolumesButton to button returned of checkVolumesResponse
	if checkVolumesButton is "Open System Preferences" then
		tell application "System Preferences"
			activate
			set current pane to pane "com.apple.preference.startupdisk"
		end tell
	end if
else
	
	--This warns the user against unsaved changes and gives an opportunity to review open documents. For a more traditional dialog, comment the next 2 lines and uncomment the following 11.
	beep --Comment this word if you dislike beeps
	set forewarnedResponse to the button returned of (display dialog return & space & "Unsaved changes abandon, ye who continue here!" buttons {"Cancel", "Save Any Changes", "Continue"} default button "Save Any Changes" with icon caution)
       --set preUnsavedSpace to ""
	--repeat 11 times
	--set preUnsavedSpace to preUnsavedSpace & space
	--end repeat
	--set unsavedSpace to preUnsavedSpace
	
	--set preProceedSpace to ""
	--repeat 20 times
	--set preProceedSpace to preProceedSpace & space
	--end repeat
	--set proceedSpace to preProceedSpace
	
	--set forewarnedResonse to button returned of (display dialog return & unsavedSpace & "Unsaved documents will be lost." & return & proceedSpace & "Proceed with caution." buttons {"Cancel", "Save Any Changes", "Continue"} default button "Save Any Changes" with icon caution)
	
	if forewarnedResponse is "Save Any Changes" then
		set preRestartSpace to ""
		repeat 8 times
			set preRestartSpace to preRestartSpace & space
		end repeat
		set restartSpace to preRestartSpace
		set preReviewSpace to ""
		repeat 3 times
			set preReviewSpace to preReviewSpace & space
		end repeat
		set reviewSpace to preReviewSpace
		
		display dialog return & restartSpace & "Restart \"uBoot\" after" & return & reviewSpace & "reviewing open documents." buttons {"Okay"} default button "Okay" with icon caution giving up after 5
		
		tell application "Finder" to close every window
		tell application "System Events"
			tell every process to set its visible to true
			
			set quitApp to name of every process whose visible is true and name is not "Finder" and name is not "uBoot"
		end tell
		
		repeat with anApp in quitApp
			tell application anApp to quit
		end repeat
		
	else
		if forewarnedResponse is "Continue" then
		end if
		
		--This sets the subroutine that restarts the computer from the chosen volume.
		
		set bootButtons to bootList
		if (count of bootButtons) < 3 then
			set bootVolume to button returned of (display dialog "Boot from which volume?" buttons (bootButtons & "Cancel") default button "Cancel")
			myChangeBoot(bootVolume, myPass)
		else
			--There is a three button maximum for dialogs; this runs if that limit is exceeded. 
			set bootVolume to (choose from list bootList)
			myChangeBoot(bootVolume, myPass)
		end if
	end if
end if

--Restart from the chosen volume.
on myChangeBoot(bootVolume, myPass)
	
	set rebootCommand to "/usr/sbin/bless -folder '/Volumes/" & bootVolume & "/System/Library/CoreServices' -setOF;/sbin/shutdown -r now"
	do shell script rebootCommand password myPass with administrator privileges
end myChangeBoot





All comments, criticisms, and suggestions have been, and continue to be, greatly appreciated.

Thanks

j

It’s when you close every window that the flurry of “save” dialogs appear because you’ve opted not to use with saving. You can’t have it both ways, I guess.

The rest looks good.