Applescript for restarting in boot camp in Catalina with TouchID

#1
Hi all,

had a quick search so hopefully I’m not treading well-trodden ground here - but apologies if I am.

I want to create an Automator quick action that restarts my mac in the Windows install I instituted via Boot Camp. I have no knowledge whatsoever about the program; I’ve been trying to learn but finding it very difficult so far.

The funny thing is, I only want this (this specific way of rebooting in windows less laboriously) because it already exists -in my hunt for a way, I found this workflow, which does the job beautifully: https://github.com/ryanmcginnis/Restart-to-Bootcamp
…Or at least it did. I upgraded my laptop to a 16" touchID model very soon after finding this and the workflow no longer works - and nor does the amendment posted on the same github for touchID macbooks :confused:. I made a post there but have not had any reply from the writers involved.

Is anyone able/willing to help me adapt or create a version of this that will work with my modern TouchID Macbook pro running Catalina? Pretty please?

Thank you!

Model: Macbook Pro Nov 2019 (TouchID) 16"
Browser: Vivaldi
Operating System: macOS 10.14

Hello,

I don’t use Bootcamp but if its partition appears as a volume in the Startup Disk pane of System Preferences the same way every mounted volume appears then I can suggest using an Automator service I created for switching into other partitions. The caveat is it doesn’t involve TouchID since I don’t own a TouchID MacBook: are you so keen to use TouchID and cannot do without it? I’ll post a Google drive link, anyway. Report if you’re unable to download it.

USAGE INSTRUCTIONS.

When you click on it upon downloading don’t hit “Install”. Go with “Open in Automator” instead.
There’s an AppleScript script snippet inside “Run AppleScript action” which utilizes GUI (graphical user interface) scripting. The most important part comes when you have to find the word “Name_Of_The_Bootcamp_partition” which serves as a placeholder and replace it with the exact name of your Bootcamp partition. To be confident everything works, try running ir from Automator first.

NOTE OF CAUTION.

Since, GUI scripting is involved there’s a high probability it will fail if the hierarchy and names of UI elements have changed as of Mojave.
I have another modification of the workflows that works around the need to enter you admin password to unlock the Startup Disk pane. If Mojave requires the admin password then the workflow will fail too. If that happens report back and I’ll upload the modified version.

https://drive.google.com/file/d/1uyQrCvyXtrGnEjsRKKCahdbsXxrCDd9N/view?usp=drivesdk

The script that this workflow uses contains GUI scripting. But if you know 1) the name of bootcamp (usually “Bootcamp”) 2) your password, then there is no need for GUI scripting.
Replace the script (in the workflow’s plist) with this:

do shell script "bless -mount /Volumes/BOOTCAMP/ -legacy -setBoot -nextonly" password "xxxxxxx" with administrator privileges
tell application "Finder" to restart

Or, better, create new, your own workflow, using Run AppleScript action… with this script. You can to not hardcode the password for security purposes.

As the scrips included in this workflow use GUIScripting, I wrote an all-in-one GUIScripting code doing the entire job.

set theBundle to ((path to library folder from system domain as string) & "PreferencePanes:StartupDisk.prefPane:") as «class furl»
set thePane to localized string "CFBundleName" from table "InfoPlist" in bundle theBundle

set thePW to "password" -- Edit to fit your needs 

tell application "System Preferences"
	reveal anchor "StartupSearchGroup" of pane id "com.apple.preference.startupdisk"
	activate
end tell
tell application "System Events" to tell process "System Preferences"
	repeat until exists window thePane
		delay 0.1
	end repeat
	tell window thePane
		-- class of UI elements --> {button, splitter group, button, button, group, button, button, button, toolbar}
		-- name of buttons --> {"Redémarrer…", "Pour modifier, cliquez sur le cadenas.", "Pour modifier, cliquez sur le cadenas.", missing value, missing value, missing value}
		delay 0.2
		click button 2 -- to unlock the pane
		repeat until exists sheet 1
			delay 0.1
		end repeat
		tell sheet 1
			-- class of UI elements --> {image, static text, image, button, static text, static text, button, text field, text field, static text}
			-- name of text fields --> {"Mot de passe", missing value}
			set value of text field 1 to thePW
			-- name of buttons --> {"Annuler", "Déverrouiller"}
			click button -1 -- "Déverrouiller"
		end tell -- sheet 1
		tell splitter group 1
			-- class of UI elements --> {group}
			tell group 1
				-- class of UI elements --> {static text, scroll area, static text}
				tell scroll area 1
					-- class of UI elements --> {radio group}
					tell radio group 1
						-- class of UI elements --> {radio button, radio button}
						-- name of every radio button --> {"Macintosh HD", "SSD 1000", "Disque Windows"}
						click radio button 2 -- the radio button pointing upon Windows volume
					end tell
				end tell
			end tell
		end tell --  splitter group 1
		click button 1 -- Redémarrer
	end tell -- window thepane
end tell -- System Events…

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 5 mai 2020 22:55:53