Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

techmonkey

macrumors 6502a
Original poster
Jun 8, 2007
596
0
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

Moderator emeritus
Jun 15, 2000
7,958
7
You can use the keystroke command:

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

techmonkey

macrumors 6502a
Original poster
Jun 8, 2007
596
0
thanks. Thats whats I was looking for.
Question though.

How can I send a Command + F in TextEdit?

So far I have this

Code:
activate application "TextEdit"

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

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Try
Code:
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

macrumors 6502a
Original poster
Jun 8, 2007
596
0
Try
Code:
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

Moderator emeritus
Jun 15, 2000
7,958
7
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.