Home > OS >  Restart Applescript causing infinite reboot loop
Restart Applescript causing infinite reboot loop

Time:06-09

I tried to set up Voice Control to restart my mac by running the applescript:

tell application "System Events"

restart

end tell

I set it up for voice control. I'd say "Restart the Mac"

However this put my mac into an infinite restart loop!

Had to trash the script.

Is there a solution to this problem with a different applescript that doesn't go into a loop? It would be great to simply say "Restart the Mac" and then presto it restarts.

CodePudding user response:

I don't think AppleScript is the best tool for this. In System Preferences→Accessibility→Voice Control you can enable Apple's built-in voice command system, which should work out-of-the-box. They don't have a built-in Restart command so you'll have to create one, but that's easy enough. Click the 'Commands...' button at the bottom right, then click the ' ' button at the bottom left, and you can choose any of several ways of implementing it.

CodePudding user response:

I use Voice Control every day, without error, to restart my computer.

These are the steps I took.

Paste this following AppleScript code into a new Script Editor document and save it as "Restart Computer.scpt" (Don't save it to any "Startup Items" Folder)

tell application "System Events" to restart

Make sure you grant access in System Preferences for System Events.app to be allowed to control your computer.

With Voice Control currently active, select the new "Restart Computer.scpt" file in Finder, then speak the command "Make This Speakable".

You Should then see a pop-up window like this...

enter image description here

Just insert the voice command you want to use (I use "Restart Computer") and click Save.

Note: Before doing all of this, you should remove any previous custom commands you have set for restarting the computer, from your Commands list in System Preferences.

As an added bonus, this following AppleScript code will reveal the file which stores all of your custom voice commands, in Finder. It's a good idea to backup this file from time to time. Also copying this file to a different computer will allow you to use the custom commands on that computer.

set customDictationCommands to (path to preferences folder as text) & ¬
    "com.apple.speech.recognition.AppleSpeechRecognition.CustomCommands.plist"

tell application "Finder" to reveal alias customDictationCommands
  • Related