×

Script: New Voice Control Commands File

Here is an AppleScript script tool (macOS) for generating a new blank Voice Control commands file containing a single placeholder (line 7-8) that you can replace with your own command(s).

The generated file has a “.voicecommands” file extension and is saved in standard Apple XML property list format.

New Voice Control Commands File (XML Property List)


<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CommandsTable</key> <dict> <key>REPLACE THIS KEY AND VALUE WITH YOUR COMMAND</key> <dict/> </dict> <key>ExportDate</key> <real>672051057.85952532</real> <key>SystemVersion</key> <dict> <key>ProductBuildVersion</key> <string>21E230</string> <key>ProductCopyright</key> <string>1983-2022 Apple Inc.</string> <key>ProductName</key> <string>macOS</string> <key>ProductUserVisibleVersion</key> <string>12.3</string> <key>ProductVersion</key> <string>12.3</string> <key>iOSSupportVersion</key> <string>15.4</string> </dict> </dict> </plist>

Property List Editor and Tools

To edit Voice Control commands files, you’ll need an XML editor application that accepts the creation of XML elements via the pasting of XML text from the clipboard. The examples and downloads provided on this website were created using PlistEdit Pro from Fat Cat Software.

DOWNLOAD SCRIPT TOOL (macOS)

  1. 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.
  2. 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.

Here is the script code written in AppleScriptObj-C:

AppleScript Script: New Voice Control Commands File


use AppleScript version "2.4" use framework "Foundation" use scripting additions -- classes, constants, and enums used property NSPropertyListBinaryFormat_v1_0 : a reference to 200 property NSPropertyListSerialization : a reference to current application's NSPropertyListSerialization property NSString : a reference to current application's NSString property NSDictionary : a reference to current application's NSDictionary property NSMutableDictionary : a reference to current application's NSMutableDictionary property NSNumberFormatter : a reference to current application's NSNumberFormatter set thePropertyListFilePath to POSIX path of (choose file name with prompt "Name and location for the new file:" default name "new-command-set.voicecontrolcommands") if thePropertyListFilePath does not end with ".voicecontrolcommands" then set thePropertyListFilePath to thePropertyListFilePath & ".voicecontrolcommands" end if set systemInfoPath to "/System/Library/CoreServices/SystemVersion.plist" set systemInfoDict to NSDictionary's dictionaryWithContentsOfFile:systemInfoPath set ProductBuildVersion to systemInfoDict's valueForKey:"ProductBuildVersion" set ProductCopyright to systemInfoDict's valueForKey:"ProductCopyright" set ProductName to systemInfoDict's valueForKey:"ProductName" set ProductUserVisibleVersion to systemInfoDict's valueForKey:"ProductUserVisibleVersion" set ProductVersion to systemInfoDict's valueForKey:"ProductVersion" set iOSSupportVersion to systemInfoDict's valueForKey:"iOSSupportVersion" set exportDateString to generateAbsoluteTimeID() set masterDict to NSMutableDictionary's new() set commandsDict to NSMutableDictionary's new() tell masterDict to setObject:commandsDict forKey:"CommandsTable" set entryDict to NSMutableDictionary's new() tell commandsDict to setObject:entryDict forKey:"REPLACE THIS KEY AND VALUE WITH YOUR COMMAND" tell masterDict to setObject:(exportDateString as real) forKey:"ExportDate" set systemEntriesDict to NSMutableDictionary's new() tell systemEntriesDict to setObject:ProductBuildVersion forKey:"ProductBuildVersion" tell systemEntriesDict to setObject:ProductCopyright forKey:"ProductCopyright" tell systemEntriesDict to setObject:ProductName forKey:"ProductName" tell systemEntriesDict to setObject:ProductUserVisibleVersion forKey:"ProductUserVisibleVersion" tell systemEntriesDict to setObject:ProductVersion forKey:"ProductVersion" tell systemEntriesDict to setObject:iOSSupportVersion forKey:"iOSSupportVersion" tell masterDict to setObject:systemEntriesDict forKey:"SystemVersion" writeAsPropertyList(masterDict, thePropertyListFilePath) display dialog "The new Voice Control commands file has been created." buttons {"Done", "Show in Finder"} default button 2 set chosenAction to the button returned of the result if chosenAction is "Show in Finder" then tell application "Finder" activate reveal (thePropertyListFilePath as POSIX file) end tell else if chosenAction is "Open in Editor" then set editingApplication to (choose application with prompt "Choose application to edit the voice commands file:") tell editingApplication activate open (thePropertyListFilePath as POSIX file) end tell end if on writeAsPropertyList(theRecord, thePath) set thePath to NSString's stringWithString:thePath set thePath to thePath's stringByExpandingTildeInPath() set savingFormat to NSPropertyListBinaryFormat_v1_0 set theData to NSPropertyListSerialization's dataWithPropertyList:theRecord format:savingFormat options:0 |error|:(missing value) theData's writeToFile:thePath atomically:true return result -- so we can see if it saved end writeAsPropertyList 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

 

 

 

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.