applescript keystroke

789 views
Skip to first unread message

blitzer

unread,
Oct 23, 2009, 12:33:18 AM10/23/09
to TextWrangler Talk
here's my script:

tell application "TextWrangler"
activate
set leftArrow to ASCII character 28
set rightArrow to ASCII character 29
set downArrow to ASCII character 31
keystroke rightArrow
keystroke downArrow
keystroke leftArrow
paste
end tell

i want the script to: press the right arrow, press the down arrow,
press the left arrow, and paste the contents of the clipboard.

paste works fine. pressing the arrows does not. it returns the
following error: Can't get keystroke "".

any ideas?

Jim Correia

unread,
Oct 24, 2009, 10:56:38 AM10/24/09
to textwr...@googlegroups.com
On Oct 23, 2009, at 12:33 AM, blitzer wrote:

> here's my script:

[…]

> i want the script to: press the right arrow, press the down arrow,
> press the left arrow, and paste the contents of the clipboard.
>
> paste works fine. pressing the arrows does not. it returns the
> following error: Can't get keystroke "".
>
> any ideas?

Consider moving the insertion point programmatically when you can.
This is usually a better solution that pushing user interface events
at the application.

If you really do need to precisely send those events to the
application, you need to do so by way of the System Events application.

tell application “TextWrangler"
activate
tell application "System Events"


set leftArrow to ASCII character 28
set rightArrow to ASCII character 29
set downArrow to ASCII character 31
keystroke rightArrow
keystroke downArrow
keystroke leftArrow

end tell
paste
end tell

- Jim

Reply all
Reply to author
Forward
0 new messages