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"
activate
try
set the current pane to pane id "com.apple.preference.universalaccess"
delay 1
reveal anchor "Dictation" of the current pane
tell application "System Events"
tell process "System Preferences"
repeat with i from 1 to 30
if exists checkbox "Enable Voice Control" of group 1 of window 1 then
exit repeat
end if
if i is 15 then error "There was a problem accessing the Voice Control preference pane."
delay 0.5
end repeat
click checkbox "Enable Voice Control" of group 1 of window 1
end tell
end tell
delay 1
quit
on error errMsg
display alert "ERROR" message errMsg
end try
end 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 later
use framework "Foundation"
use scripting additions
-- classes, constants, and enums used
property NSNumberFormatter : a reference to current application's NSNumberFormatter
property NSString : a reference to current application's NSString
set IDString to ("Custom." & generateAbsoluteTimeID()) as string
set the clipboard to IDString
display dialog "The following key is on the clipboard:" & linefeed & linefeed & IDString with title "Voice Control Command ID" buttons {"OK"} default button 1
on generateAbsoluteTimeID()
## 669490008.038141
set 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 string
if length of exportDateString is not 23 then
repeat until length of exportDateString is 18
set exportDateString to exportDateString & (random number from 1 to 9) as string
end repeat
end if
return exportDateString
end 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 later
use framework "Foundation"
use scripting additions
-- classes, constants, and enums used
property NSNumberFormatter : a reference to current application's NSNumberFormatter
property NSString : a reference to current application's NSString
property NSCharacterSet : a reference to current application's NSCharacterSet
property errorWrapOpening : "try {
// check for existing document
var currentDoc = document
// execute the script
"
property errorWrapClosing : "
}
catch (err){
console.log(err)
}"
try
set 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 text
set textLength to item 2 of item 1 of clipInfo
if textLength is 0 then error "There is no text on the clipboard."
set contentsOfSelection to get the clipboard as Unicode text
set 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 -128
set lowercaseAppName to my changeCaseOfText((targetAppName as string), 1)
display dialog "Wrap the script with error handler?" buttons {"Cancel", "Yes", "No"} default button 3
set shouldWrap to (the button returned of the result) as boolean
if shouldWrap is true then
set textWithErrorHandler to errorWrapOpening & tab & contentsOfSelection & errorWrapClosing
set encodedString to my encodeUsingPercentEncoding(textWithErrorHandler)
else
set encodedString to my encodeUsingPercentEncoding(contentsOfSelection)
end if
--set encodedString to my encodeUsingPercentEncoding(contentsOfSelection)
set the scriptURL to lowercaseAppName & "://localhost/omnijs-run?script=" & encodedString
set the clipboard to scriptURL
display dialog "The encosed script URL is on the clipboard." with title "Encode Omni Automation Script"
on error errorMsg number errorNum
if errorNum is not -128 then
display alert "Error" message errorMsg
end if
end try
on 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 encoded
set allowedCharacterSet to NSCharacterSet's alphanumericCharacterSet
-- apply the indicated transformation to the Cooca string
set the adjustedString to the sourceString's stringByAddingPercentEncodingWithAllowedCharacters:(allowedCharacterSet)
-- convert from Cocoa string to AppleScript string
return (adjustedString as string)
on error msg
display dialog msg
end try
end encodeUsingPercentEncoding
on 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 string
if the caseIndicator is 0 then
set the adjustedString to sourceString's uppercaseString()
else if the caseIndicator is 1 then
set the adjustedString to sourceString's lowercaseString()
else
set the adjustedString to sourceString's capitalizedString()
end if
-- convert from Cocoa string to AppleScript string
return (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.4
utterance = new Speech.Utterance(textToSpeak)
utterance.voice = voiceObj
utterance.rate = voiceRate
return utterance
}
var synthesizer = new Speech.Synthesizer()
// SELECTION CHECK GOES HERE
// PROCESSING STATEMENTS GO HERE
utterance = 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.4
utterance = new Speech.Utterance(textToSpeak)
utterance.voice = voiceObj
utterance.rate = voiceRate
return utterance
}
var synthesizer = new Speech.Synthesizer()
// CREATE TEXT FIELD OBJECT
var textInputField = new Form.Field.String(
"textInput",
null,
null,
null
)
// CREATE NEW FORM AND ADD FIELD
var inputForm = new Form()
inputForm.addField(textInputField)
// VALIDATE USER INPUT
inputForm.validate = function(formObject){
textInput = formObject.values["textInput"]
if (!textInput){return false}
return true
}
// DISPLAY THE FORM
var 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 INPUT
textInput = formObject.values["textInput"]
// RESPOND USING INPUT
utterance = 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.