Script Extras
Here are some AppleScript script tools (macOS) for working with Voice Control and commands files.
Show Voice Control Preferences
Simple script executes a special Apple URL to display the Voice Control tab of the Accessibility system preferences pane.
⇩ DOWNLOAD SCRIPT TOOL (macOS)
- To install the script file, DOWNLOAD and run the “Setup Script Menu” applet. This script applet will turn on the system-wide “Script Menu,” and open the macOS “Scripts” folder on the desktop. This process may require your approval of security dialogs, granting this script applet access to the “AppleScript Utility” and “Finder” applications.
- Unpack the downloaded ZIP archive containing the script tool, and place the script file into the “Scripts” folder now open on the Desktop. Once added, the script will be available from the system-wide “Script Menu” located at the top right of the menu bar.
Show Voice Control Preferences
open location "x‑apple.systempreferences:com. "apple. preference. universalaccess? Dictation 
Toggle Voice Control
This script uses the System Events application (UI Scripting) to enable and disable Voice Control in the system preference pane.
NOTE: Requires the one-time approval of Apple Events access in the security dialog displayed during the 1st run of the script.
⇩ DOWNLOAD SCRIPT TOOL (macOS)
- To install the script file, DOWNLOAD and run the “Setup Script Menu” applet. This script applet will turn on the system-wide “Script Menu,” and open the macOS “Scripts” folder on the desktop. This process may require your approval of security dialogs, granting this script applet access to the “AppleScript Utility” and “Finder” applications.
- Unpack the downloaded ZIP archive containing the script tool, and place the script file into the “Scripts” folder now open on the Desktop. Once added, the script will be available from the system-wide “Script Menu” located at the top right of the menu bar.
Toggle Voice Control
tell application "System Preferences"activatetryset the current pane to pane id "com.apple.preference.universalaccess"delay 1reveal anchor "Dictation" of the current panetell application "System Events"tell process "System Preferences"repeat with i from 1 to 30if exists checkbox "Enable Voice Control" of group 1 of window 1 thenexit repeatend ifif i is 15 then error "There was a problem accessing the Voice Control preference pane."delay 0.5end repeatclick checkbox "Enable Voice Control" of group 1 of window 1end tellend telldelay 1quiton error errMsgdisplay alert "ERROR" message errMsgend tryend tell
Generate Custom Command ID
This script will generate a Custom Voice Control Command Identifier and place it on the clipboard.
⇩ DOWNLOAD SCRIPT TOOL (macOS)
- To install the script file, DOWNLOAD and run the “Setup Script Menu” applet. This script applet will turn on the system-wide “Script Menu,” and open the macOS “Scripts” folder on the desktop. This process may require your approval of security dialogs, granting this script applet access to the “AppleScript Utility” and “Finder” applications.
- Unpack the downloaded ZIP archive containing the script tool, and place the script file into the “Scripts” folder now open on the Desktop. Once added, the script will be available from the system-wide “Script Menu” located at the top right of the menu bar.
Generate Custom Command ID
use AppleScript version "2.4" -- Yosemite (10.10) or lateruse framework "Foundation"use scripting additions-- classes, constants, and enums usedproperty NSNumberFormatter : a reference to current application's NSNumberFormatterproperty NSString : a reference to current application's NSStringset IDString to ("Custom." & generateAbsoluteTimeID()) as stringset the clipboard to IDStringdisplay dialog "The following key is on the clipboard:" & linefeed & linefeed & IDString with title "Voice Control Command ID" buttons {"OK"} default button 1on generateAbsoluteTimeID()## 669490008.038141set currentAbsoluteTime to current application's CFAbsoluteTimeGetCurrent()set fmtr to NSNumberFormatter's new()fmtr's setFormat:"#.#########"set exportDateString to NSString's stringWithFormat_("%@", fmtr's stringFromNumber:currentAbsoluteTime) as stringif length of exportDateString is not 23 thenrepeat until length of exportDateString is 18set exportDateString to exportDateString & (random number from 1 to 9) as stringend repeatend ifreturn exportDateStringend generateAbsoluteTimeID
Encode Omni Automation Script
This script will replace the contents of the clipboard with an encoded script URL of the Omni Automation script that is currently on the clipboard.
⇩ DOWNLOAD SCRIPT TOOL (macOS)
- To install the script file, DOWNLOAD and run the “Setup Script Menu” applet. This script applet will turn on the system-wide “Script Menu,” and open the macOS “Scripts” folder on the desktop. This process may require your approval of security dialogs, granting this script applet access to the “AppleScript Utility” and “Finder” applications.
- Unpack the downloaded ZIP archive containing the script tool, and place the script file into the “Scripts” folder now open on the Desktop. Once added, the script will be available from the system-wide “Script Menu” located at the top right of the menu bar.
Encode Omni Automation Script
use AppleScript version "2.4" -- Yosemite (10.10) or lateruse framework "Foundation"use scripting additions-- classes, constants, and enums usedproperty NSNumberFormatter : a reference to current application's NSNumberFormatterproperty NSString : a reference to current application's NSStringproperty NSCharacterSet : a reference to current application's NSCharacterSetproperty errorWrapOpening : "try {// check for existing documentvar currentDoc = document// execute the script"property errorWrapClosing : "}catch (err){console.log(err)}"tryset dialogMessage to "This script will create a script URL using the Omni Automation script currently copied to the clipboard."display dialog dialogMessage with title "Encode Omni Automation Script"set clipInfo to clipboard info for Unicode textset textLength to item 2 of item 1 of clipInfoif textLength is 0 then error "There is no text on the clipboard."set contentsOfSelection to get the clipboard as Unicode textset targetAppName to (choose from list {"OmniOutliner", "OmniGraffle", "OmniPlan", "OmniFocus"} with prompt "Target the Omni Automation script with which application?")if targetAppName is false then error number -128set lowercaseAppName to my changeCaseOfText((targetAppName as string), 1)display dialog "Wrap the script with error handler?" buttons {"Cancel", "Yes", "No"} default button 3set shouldWrap to (the button returned of the result) as booleanif shouldWrap is true thenset textWithErrorHandler to errorWrapOpening & tab & contentsOfSelection & errorWrapClosingset encodedString to my encodeUsingPercentEncoding(textWithErrorHandler)elseset encodedString to my encodeUsingPercentEncoding(contentsOfSelection)end if--set encodedString to my encodeUsingPercentEncoding(contentsOfSelection)set the scriptURL to lowercaseAppName & "://localhost/omnijs-run?script=" & encodedStringset the clipboard to scriptURLdisplay dialog "The encosed script URL is on the clipboard." with title "Encode Omni Automation Script"on error errorMsg number errorNumif errorNum is not -128 thendisplay alert "Error" message errorMsgend ifend tryon encodeUsingPercentEncoding(sourceText)try-- create a Cocoa string from the passed AppleScript string, by calling the NSString class method stringWithString:set the sourceString to NSString's stringWithString:sourceText-- indicate the allowed characters that do not get encodedset allowedCharacterSet to NSCharacterSet's alphanumericCharacterSet-- apply the indicated transformation to the Cooca stringset the adjustedString to the sourceString's stringByAddingPercentEncodingWithAllowedCharacters:(allowedCharacterSet)-- convert from Cocoa string to AppleScript stringreturn (adjustedString as string)on error msgdisplay dialog msgend tryend encodeUsingPercentEncodingon changeCaseOfText(sourceText, caseIndicator)-- create a Cocoa string from the passed text, by calling the NSString class method stringWithString:set the sourceString to NSString's stringWithString:sourceText-- apply the indicated transformation to the Cocoa stringif the caseIndicator is 0 thenset the adjustedString to sourceString's uppercaseString()else if the caseIndicator is 1 thenset the adjustedString to sourceString's lowercaseString()elseset the adjustedString to sourceString's capitalizedString()end if-- convert from Cocoa string to AppleScript stringreturn (adjustedString as string)end changeCaseOfText
New Asynchronous JS Voice Command Wrapper (Omni Automation)
This script will replace the contents of the clipboard with the code for a new asynchronous JavaScript Voice Command wrapper template that incorporates use of the Speech.Voice class in Omni Automation to communicate with the user.
⇩ DOWNLOAD SCRIPT TOOL (macOS)
- To install the script file, DOWNLOAD and run the “Setup Script Menu” applet. This script applet will turn on the system-wide “Script Menu,” and open the macOS “Scripts” folder on the desktop. This process may require your approval of security dialogs, granting this script applet access to the “AppleScript Utility” and “Finder” applications.
- Unpack the downloaded ZIP archive containing the script tool, and place the script file into the “Scripts” folder now open on the Desktop. Once added, the script will be available from the system-wide “Script Menu” located at the top right of the menu bar.
Asynchronous JS Voice Command Wrapper (Omni Automation)
(async () => {try {function createUtterance(textToSpeak){AlexID = ((app.platformName === "macOS") ?"com.apple.speech.synthesis.voice.Alex" :"com.apple.speech.voice.Alex")voiceObj = Speech.Voice.withIdentifier(AlexID)voiceRate = 0.4utterance = new Speech.Utterance(textToSpeak)utterance.voice = voiceObjutterance.rate = voiceRatereturn utterance}var synthesizer = new Speech.Synthesizer()// SELECTION CHECK GOES HERE// PROCESSING STATEMENTS GO HEREutterance = createUtterance("Done!")synthesizer.speakUtterance(utterance)}catch(err){utterance = createUtterance(err.message)synthesizer.speakUtterance(utterance)//new Alert(err.name, err.message).show()}})();
⇩ DOWNLOAD SCRIPT TOOL (macOS)
- To install the script file, DOWNLOAD and run the “Setup Script Menu” applet. This script applet will turn on the system-wide “Script Menu,” and open the macOS “Scripts” folder on the desktop. This process may require your approval of security dialogs, granting this script applet access to the “AppleScript Utility” and “Finder” applications.
- Unpack the downloaded ZIP archive containing the script tool, and place the script file into the “Scripts” folder now open on the Desktop. Once added, the script will be available from the system-wide “Script Menu” located at the top right of the menu bar.
Asynchronous JS Voice Command Wrapper with Form (Omni Automation)
(async () => {try {function createUtterance(textToSpeak){AlexID = ((app.platformName === "macOS") ?"com.apple.speech.synthesis.voice.Alex" :"com.apple.speech.voice.Alex")voiceObj = Speech.Voice.withIdentifier(AlexID)voiceRate = 0.4utterance = new Speech.Utterance(textToSpeak)utterance.voice = voiceObjutterance.rate = voiceRatereturn utterance}var synthesizer = new Speech.Synthesizer()// CREATE TEXT FIELD OBJECTvar textInputField = new Form.Field.String("textInput",null,null,null)// CREATE NEW FORM AND ADD FIELDvar inputForm = new Form()inputForm.addField(textInputField)// VALIDATE USER INPUTinputForm.validate = function(formObject){textInput = formObject.values["textInput"]if (!textInput){return false}return true}// DISPLAY THE FORMvar formPrompt = "Enter or dictate the text to use:"var buttonTitle = "Continue"utterance = createUtterance("Ready!")synthesizer.speakUtterance(utterance)var formObject = await inputForm.show(formPrompt, buttonTitle)// RETRIVE FORM INPUTtextInput = formObject.values["textInput"]// RESPOND USING INPUTutterance = createUtterance(textInput)synthesizer.speakUtterance(utterance)}catch(err){if(!err.causedByUserCancelling){utterance = createUtterance(err.message)synthesizer.speakUtterance(utterance)//new Alert(err.name, err.message).show()}}})();
LEGAL
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. OMNI-AUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. OMNI-AUTOMATION.COM provides this only as a convenience to our users. OMNI-AUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and OMNI-AUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from OMNI-AUTOMATION.COM and that OMNI-AUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.