Boot to Macintosh HD 1, launch Keychain Access and create a new generic password item with the name boot_key in your login keychain with the following attributes (replace "klanomath" with your admin user name and "Passw0rd" with your admin user's password):
The password is self-evidently also klanomath's login password. security is always allowed to use the key! The exec security can be found in /usr/bin/.
Then open Automator and create a new service.
- Set "Service receives" to "no input" in "any application"
Add the action "Run AppleScript" and paste the following code (replace klanomath with your admin's user name below):
on run {input, parameters}
do shell script "security 2>&1 >/dev/null find-generic-password -gl \"boot_key\" | awk '{print $2}'"
set myPass to (text 2 thru -2 of result) as text
do shell script "systemsetup -setstartupdisk \"/Volumes/Macintosh HD 2/System/Library/CoreServices\"" user name "klanomath" password myPass with administrator privileges
tell application "System Events"
set appList to the name of every process whose background only is false
end tell
repeat with theApp in appList
try
tell application theApp to quit
end try
end repeat
do shell script "shutdown -r now" user name "klanomath" password myPass with administrator privileges
return input
end run
Screenshot of Automator:
The middle part of the AppleScript (tell application "System Events"... tries to quit all open apps gracefully.
- Compile and save the service (in my example the name is change_bootdisk)
- The service will be saved to ~/Library/Services
Open System Preferences > Keyboard > Shortcuts > Services, choose the service name and apply a shortcut (in my example altcmdB).
On your other boot volume you have to perform the same steps but replace the boot drive in the second do shell script:
do shell script "systemsetup -setstartupdisk \"/Volumes/Macintosh HD 1/System/Library/CoreServices\"" user name "klanomath" password myPass with administrator privileges
bless
command usesystemsetup
(e.gsudo systemsetup -setstartupdisk /Volumes/Macintosh\ HD\ 2
booted to Macintosh HD 1 orsudo systemsetup -setstartupdisk /Volumes/Macintosh\ HD\ 1
booted to Macintosh HD 2). Remove the dialog part from the AS (the first seven lines), save it as service and apply a short cut.