How to send keystrokes from Vuo with Applescript?

When I use this script with applescript it works perfect:

tell application "System Events" to keystroke "r" using {option down, command down}

With execute shell command I use:

#!/usr/bin/osascript
tell application "System Events" to keystroke "r" using {option down, command down}

and nothing happens. on the output I get (see picture)

What am I making wrong? It is possible to send a keystroke from VUO ?
thanks

I think it might have something to do with quoting when using a shell script.

Check out
https://macscripter.net/viewtopic.php?id=46949

You can probably find out what you need to escape and you’ll probably have to do it yourself.

You could use the AppleScript function they discuss “quoted form of”. Run it in AppleScript on the string. Then Log it or view the result in your editor.

It is what I had written. In script-editor it works correctly but not in Vuo node “execute shell command” and I can’t find anywhere the correct notation for this node. I have tried:

`#!/usr/bin/osascript
tell application "System Events" to keystroke "r" using {option down, command down}`

but it doesn’t run.

I’m pretty sure you have to escape the double quotes and possibly the { and }

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  

Thanks, @technomorph.

@jfg,
Unfortunately, Vuo’s Execute Shell Command executes commands in a sandbox, which prevents performing system-wide actions such as sending a keystroke. If you’re trying to refresh a webpage (⌘⌥R is the shortcut for refreshing a webpage in Safari), then maybe you can use Vuo’s Make Image from Web Page node.

Of possible interest is the Feature Request, Key event emulator.