Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I have an applescript that needs to be called by an external program with command-shift-click. However, the applescript then performs keystrokes with command & shift held down. How do I get around this?

I tried:

keystroke "blah" using command up

but get this syntax error: Expected end of line, etc. but found application constant or consideration.

I've similarly tried

key up shift
key up command
keystroke "blah"

and this simply doesn't work - the command/shift keys are still held.

Is using documented anywhere that might help me resolve this? Otherwise, how do you make the applescript ignore user-held modifier keys?

EDIT: A workaround (but not a solution): http://stackoverflow.com/questions/6584357/why-applescript-always-send-keystrokes-with-command-down add delay 0.2 before the script

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Well, hard to prove a negative but, as the question you linked to yourself says: you are holding the and keys down when calling the script. It can not ignore them. Apple script is scripting, and much closer to GUI scripting than to applicative scripting.

I cannot offer any other idea than in the answer to the question you sent: just add a slight delay so that you release the keys before the keystrokes are sent.

delay 0.2
share|improve this answer
    
So there's no way to override the keyboard for lifting the key? Because key down DOES override the keyboard; as far as I could tell, the only way to undo an applescript key down command is a key up command. The real problem is that, if I accidentally hold the key down 0.1 seconds too long, the simple series of harmless ascii characters get transformed into extremely destructive quit / close / save etc. commands –  keflavich Jan 12 '12 at 22:08
    
@keflavich Well, key down does not so much override as complete the current keyboard state… –  MattiSG Jan 13 '12 at 7:44

FastScripts pauses running scripts before keystroke and key code commands if modifier keys have not been released.

One cool trick in 2.6.1 is the way FastScripts behaves when your scripts include “keystroke” commands to synthesize keyboard presses. In the past, these scripts were tricky to get right in FastScripts, because the synthesized keystroke would be mixed up with the very keys you had used to invoke the script. Now, FastScripts will suspend execution of any such script until you release the keys that were pressed to invoke the script.

FastScripts does not support triggering scripts with pointing device actions, but you could use KeyRemap4MacBook to map pointing device actions to some unused key combinations first.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.