Monday, December 18, 2017

#1 2017-09-28 06:01:02 pm

SFinSF
Member
Registered: 2017-09-26
Posts: 1

Help with Key Code command — Not Executing

Hey all. I'm trying to write a script for InDesign that incorporates a macro from Keyboard Maestro. Basically it's goal is to expand the screen and set the workspace for a second monitor. Currently the script activates InDesign, but the key code doesn't execute.

Here's what I'm working with:

Applescript:


if application "Adobe InDesign CC 2017" is running then
   tell application "Adobe InDesign CC 2017"
       activate
       delay 0.1
       tell application "System Events" to key code 80
   end tell
end if

I'm a not very versed in this, so go gentle. Thanks in advance for any help.

Model: MBP
AppleScript: 2.5
Browser: Safari 537.36
Operating System: Mac OS X (10.12.5)

Offline

 

#2 2017-09-29 03:58:00 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3203

Re: Help with Key Code command — Not Executing

You failed to define the target process.

Applescript:

if application "Adobe InDesign CC 2017" is running then
   tell application "Adobe InDesign CC 2017"
       activate
       delay 0.1
       tell application "System Events" to tell process "Adobe InDesign" # I'm not sure of the exact name of the process
       set frontmost to true
       key code 80
       end tell
   end tell
end if

Yvan KOENIG running Sierra 10.12.6 in French (VALLAURIS, France) vendredi 29 septembre 2017 10:57:14

Offline

 

#3 2017-09-29 07:20:44 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 4460

Re: Help with Key Code command — Not Executing

Hi SFinSF.

As far as I can find out, key number 80 is the F19 key on an extended keyboard. I presume that this key exists on your keyboard and that it's programmed to do something in inDesign when simply pressed with no modifier keys.

I've had no success myself this morning trying to operate function keys with keystroke or key code, so it may not actually be possible. But hopefully someone will be able to contradict me in this respect.


Yvan Koenig wrote:

You failed to define the target process.


Hi Yvan.

Although key code and keystroke are listed under the Processes Suite in System Events's scripting dictionary, it still seems to be the case in Sierra that keyboard events are sent to the frontmost process whatever that may happen to be at the time.

Applescript:

tell application "TextEdit" to activate
delay 2 -- To give time to let go of the Command key.
tell application "System Events" to keystroke "Hello"

Applescript:

tell me to activate
delay 2 -- To give time to let go of the Command key.
tell application "System Events" to tell application process "TextEdit" to keystroke "Hello"

Both commands still also work when UI elements enabled is false.


NG

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)