use AppleScript version “2.4” – Yosemite (10.10) or later
use framework “Foundation”
use scripting additions
set shell to "tell application 'System Events' to keystroke 'r' using {option down, command down}"
set shellQuote to quoted form of shell
log {"shell is:", shell}
log {"shellQuote is:", shellQuote}
--tell application "System Events" to keystroke "r" using {option down, command down}
** Notice that I had to use single quotes instead of double to create the shell string
When I run this the properties are:
Shell:
tell application 'System Events' to keystroke 'r' using {option down, command down}
shellQuote:
'tell application '\''System Events'\'' to keystroke '\''r'\'' using {option down, command down}'
From the Script Dictionary for System Events on the Text Class:
quoted form
A rendering of the text string suitable for handing to the shell as an argument to a command. The text string is wrapped in single quotation marks and internal quotation marks are escaped.
You also may want to try the System Events Command:
key code
key code (verb)cause the target process to behave as if key codes were entered (from Processes Suite)
COMMAND SYNTAX
key code integer or list of integer ¬
using using or list of using
PARAMETERS
Parameter
Required
Type
Description
direct parameter required integer or list of integer The key code(s) to be sent. May be a list.
using optional using or list of using modifiers with which the key codes are to be entered