Script: New Run Shortcut Voice Control Command
Here is an AppleScript script tool (macOS) for generating the XML of a new Voice Control Run Shortcut command. The script will generate the values for all of the placeholders (shown in orange) and place the resulting XML on the clipboard.
New Run Shortcut Command XML (system-wide scope)
<key>COMMAND-ID</key><dict><key>CustomCommands</key><dict><key>LOCALE-CODE</key><array><string>MENU-ITEM-TITLE</string></array></dict><key>CustomModifyDate</key><date>ISO-DATE-STRING</date><key>CustomScope</key><string>com.apple.speech.SystemWideScope</string><key>CustomShortcutsWorkflow</key><string>SHORTCUT-ID</string><key>CustomType</key><string>RunShortcutsWorkflow</string><key>Enabled</key><true/></dict>
New Run Shortcut Command XML (app scope)
<key>COMMAND-ID</key><dict><key>CustomAppName</key><string>TARGET-APP-NAME</string><key>CustomCommands</key><dict><key>LOCALE-CODE</key><array><string>MENU-ITEM-TITLE</string></array></dict><key>CustomModifyDate</key><date>ISO-DATE-STRING</date><key>CustomScope</key><string>TARGET-APP-ID</string><key>CustomShortcutsWorkflow</key><string>SHORTCUT-ID</string><key>CustomType</key><string>RunShortcutsWorkflow</string><key>Enabled</key><true/></dict>
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)
- 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.
Here is the script code written in AppleScriptObj-C:
AppleScript Script: New Run Shortcut Voice Control Command
use AppleScript version "2.4" -- Yosemite (10.10) or lateruse framework "Foundation"use scripting additions-- classes, constants, and enums usedproperty NSUserDefaults : a reference to current application's NSUserDefaultsproperty NSNumberFormatter : a reference to current application's NSNumberFormatterproperty NSString : a reference to current application's NSStringproperty scriptID : "com.nyhthawk-productions.script.vc-run-shortcut-command"property defaultTargetAppName : "Finder"property defaultTargetAppID : "com.apple.finder"global targetAppName, targetAppID## USER DEFAULTSset theDefaults to NSUserDefaults's alloc()'s initWithSuiteName:scriptIDtheDefaults's registerDefaults:{targetAppName:defaultTargetAppName, targetAppID:defaultTargetAppID}set targetAppName to (theDefaults's stringForKey:"targetAppName") as stringset targetAppID to (theDefaults's stringForKey:"targetAppID") as string## USER PROMPTrepeatset dialogMessage to "This script will generate the XML text for a new Run Shortcuts Voice Control command element." & returnset dialogMessage to dialogMessage & return & "Target Application: " & targetAppNameset dialogMessage to dialogMessage & return & "Application ID: " & targetAppIDdisplay dialog dialogMessage with title "Voice Control Command: Key-Combo" buttons {"Cancel", "Set App", "Continue"} default button 3set actionChoice to the button returned of the resultif actionChoice is "Continue" thenexit repeatelse if actionChoice is "Set App" thenset targetApp to choose application with prompt "Select the application to use:"tell targetAppset targetAppID to the id of itset targetAppName to the name of itend telltheDefaults's setObject:targetAppID forKey:"targetAppID"theDefaults's setObject:targetAppName forKey:"targetAppName"end ifend repeat## PROMPT USER FOR SCOPEdisplay dialog "Should this Voice Control command be available only in " & (targetAppName as string) & " or System-Wide?" with title "Availability of Voice Control Command" buttons {"Cancel", "System-Wide", targetAppName} default button 3set chosenScope to the button returned of the result## SHORTCUTS COMMUNICATIONtell application "Shortcuts Events"set shortcutTitles to the name of every shortcutend tell## PROMPT USER TO SELECT SHORTCUTset shortcutTitle to choose from list shortcutTitles with prompt "Select the shortcut for the command:"if shortcutTitle is false then error number -128set shortcutTitle to shortcutTitle as string## GET ID OF CHOSEN SHORTCUTtell application "Shortcuts Events"set shortcutID to the id of shortcut shortcutTitleend tell## GENERATE THE COMMAND IDset IDstring to ("Custom." & generateAbsoluteTimeID()) as string## GENERATE THE CURRENT DATE IN ISO FORMATset dateString to do shell script "date +'%Y-%m-%dT%H:%M:%SZ'"## GET THE CURRENT LOCALEset localeString to user locale of (system info)## GENERATE CORRESPONDING XMLif chosenScope is "System-Wide" thenset commandXML to " <key>" & IDstring & "</key><dict><key>CustomCommands</key><dict><key>" & localeString & "</key><array><string>" & shortcutTitle & "</string></array></dict><key>CustomModifyDate</key><date>" & dateString & "</date><key>CustomScope</key><string>com.apple.speech.SystemWideScope</string><key>CustomShortcutsWorkflow</key><string>" & shortcutID & "</string><key>CustomType</key><string>RunShortcutsWorkflow</string><key>Enabled</key><true/></dict>"elseset commandXML to " <key>" & IDstring & "</key><dict><key>CustomAppName</key><string>" & targetAppName & "</string><key>CustomCommands</key><dict><key>" & localeString & "</key><array><string>" & shortcutTitle & "</string></array></dict><key>CustomModifyDate</key><date>" & dateString & "</date><key>CustomScope</key><string>" & targetAppID & "</string><key>CustomShortcutsWorkflow</key><string>" & shortcutID & "</string><key>CustomType</key><string>RunShortcutsWorkflow</string><key>Enabled</key><true/></dict>"end if## COPY XML TO CLIPBOARDset the clipboard to commandXML## USER PROMPTdisplay dialog "The XML text for a new Shortcuts Workflow Voice Command is on the clipboard." buttons {"OK"} default button 1 with title "Voice Control Command: Run Shortcuts Workflow"on 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
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.