Keyboard Script Problem...
  • Hi:

    Rather strange problem... I have a keyboard script to close the top window in the frontmost app which had been working perfectly for weeks (since I first purchased FastScripts). Now - when invoked from the key command - the script (intermittently, of course) insists on closing all windows the app has open. When called from the FastScripts menu, it works as intended.

    I was successfully using Command-Option-Down Arrow to call the script, and have tried other combos (not involving Option), but the problem persists.

    On a hunch, I tossed FastScripts' .plist and re-entered my key combos. No luck. I reverted to 2.29. Still no luck.

    The script is below...

    Any suggestions or workarounds?

    Thanks Very Much.

    Peter B.

    OS 10.4.3

    --


    tell application "System Events"
    delay 0.2
    tell (every process whose frontmost is true and visible is true)
    delay 0.2
    keystroke "w" using command down
    end tell
    end tell

    -----
  • Hi Peter - the best thing to try is increasing the delay - perhaps by a ridiulous amoung, to make sure it's not a key conflict issue. It's a problem with UI scripting that it combines whatever keys are beind held down with the keystrokes it's instructed to generate. And sometimes even if it's not option, it can cause weird behavior. I would increase the delay to something big like "1.0" to see if you get regular behavior again, then gradually reduce it until you find a value that lets you comfortably release the keys in time.

    I think I might have an idea for working around this, if I provide my own keystroke-generating functionality in FastScripts itself. I'm going to look into providing this in a future release.

    Also, for this particular case, I would alter the script so that it only uses GUI scripting as a last resort. For instance, most apps will respond to a request to "close window 1", which will (should) always be the front window.

    tell application \"System Events\"
    set targetAppName to name of first process whose frontmost is true and visible is true
    end tell
    try
    tell application targetAppName
    close window 1
    end tell
    on error
    tell application \"System Events\"
    tell (every process whose frontmost is true and visible is true)
    delay 0.5
    keystroke \"w\" using command down
    end tell
    end tell
    end try

    That way you'll only get the delay, and the potential for trouble, in the case that the app doesn't support the "close window" command.

    Hope this helps.

    Daniel
  • Daniel:

    Thank you... your modification to the script seems to be working nicely.

    I don't guess I'd have bothered you, but found it odd my own version simply stopped working properly.

    Maybe FastScripts gets 'faster' with age...

    Regards,

    Peter B.

    -----
  • >> Maybe FastScripts gets 'faster' with age...

    Heh - that's a problem I think I could learn to live with. :)

    Glad the new script is working for you...

    Daniel
Start a New Discussion

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!