Does Applescript have a "SendKey" type command?

Discussion in 'Mac Programming' started by techmonkey, Feb 17, 2008.

  1. macrumors 6502a

    Joined:
    Jun 8, 2007
    #1
    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.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    You can use the keystroke command:

    Code:
    tell application "System Events"
    	keystroke "#" using {command down, shift down}
    end tell
    (takes a screen shot)
     
  3. thread starter macrumors 6502a

    Joined:
    Jun 8, 2007
    #3
    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
    
    
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. thread starter macrumors 6502a

    Joined:
    Jun 8, 2007
    #5

    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?
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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.

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

Share This Page