PDA

View Full Version : Does Applescript have a "SendKey" type command?




techmonkey
Feb 17, 2008, 07:26 PM
Coming from the Windows world, Im use to having a SendKey command in VB/VBA in programming. Is there something similar in Applescript?

What I am trying to do is run some keys whenever a specified window pops-up.



kainjow
Feb 17, 2008, 07:59 PM
You can use the keystroke command:

tell application "System Events"
keystroke "#" using {command down, shift down}
end tell
(takes a screen shot)

techmonkey
Feb 17, 2008, 08:44 PM
thanks. Thats whats I was looking for.
Question though.

How can I send a Command + F in TextEdit?

So far I have this



activate application "TextEdit"

tell application "System Events"
keystroke "F"
end tell

kainjow
Feb 17, 2008, 08:49 PM
Try
tell application "TextEdit"
activate

tell application "System Events"
keystroke "f" using {command down}
end tell
end tell

You might want to learn GUI scripting with AppleScript, which lets you control parts of an application that aren't normally scriptable.

techmonkey
Feb 17, 2008, 09:02 PM
Try
tell application "TextEdit"
activate

tell application "System Events"
keystroke "f" using {command down}
end tell
end tell

You might want to learn GUI scripting with AppleScript, which lets you control parts of an application that aren't normally scriptable.


Thanks.

Hmm... How come it says Command Down for the command key? Whats the down for?

Do you have a good resouce for GUI scripting with Applescript?

kainjow
Feb 17, 2008, 09:08 PM
How come it says Command Down for the command key? Whats the down for?

It's the name of the parameter to the keystroke command. In Script Editor, go to File > Open Dictionary, select System Events, then search for "keystroke" and you'll see the other options.

Do you have a good resouce for GUI scripting with Applescript?

Apple's site is a good starter: http://www.apple.com/applescript/uiscripting/