5 Replies Latest reply: Apr 4, 2010 11:54 AM by Pierre Igot
Pierre Igot Level 1 Level 1 (15 points)
Hi,

I am having the following problem. I have an AppleScript script for Pages that I want to trigger with a keyboard shortcut involving the Command key. (I am using Keyboard Maestro for this, but the same problem applies when I use FastScript.)

The problem is that the script in question contains a step where I tell System Events to tell Pages to type a key. And I want Pages to type the key WITHOUT any modifier key:

<pre>
tell application "System Events" to tell application process "Pages"
key code 36
end tell
</pre>

But the script executes so fast that by the time it reaches this step, half of the time my finger has not quite released the Command key that I pressed for the keyboard shortcut to trigger the script. And when that happens System Events still treats the Command key as being down and so executes "key code 36" as if it were "key code 36 using command down".

But I don't want this! Whether I have released the Command key yet or not, I want the script to always execute "key code 36" without a modifier key.

Is this possible?

I can't find any reference to this particular problem.

Of course, when I run the script by invoking it with something that involves the mouse, there is no problem whatsoever. But that's not a solution. I want to be able to invoke the script with the a keyboard shortcut.

I could also use a keyboard shortcut that doesn't involve a modifier key, like an Fkey, but that would not be the most convenient for me.

And I could probably add a pause in the script to wait until my finger has released the modifier keys. But that strikes me as particularly inelegant, considering that I am a fast typist and wants all my commands, including this one, to execute as fast as possible.

So, basically, my question is: Is there a way to make this "key code 36" command execute in a way that ignores whatever modifier keys might still be halfway down? I naively tried "key code 36 not using command down" and "key code 36 using command up", but neither worked for me.

I would appreciate feedback on this.

Mac Pro 2x2.26, Mac OS X (10.6.3)