trigger spacebar key through terminal or applescipt

Discussion in 'macOS' started by dikketienes, Apr 1, 2010.

  1. dikketienes macrumors member

    Joined:
    Oct 13, 2008
    #1
    Hi,

    I want to trigger a spacebar keystroke through the terminal or applescript.
    I don't know if it is possible, maybe someone can tell me?

    Greets Dick
     
  2. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #2
    Are you wanting to send this to a particular application?

    To get started, you have to "Enable access for assistive devices" in Universal Access.

    From there you can use AppleScript, for example:

    Code:
    tell application "Finder"
    	activate
    	tell application "System Events" to key code 40 using command down
    end tell
    
    That script would activate Finder and open the "Connect to Server" (command + k) dialog.

    Here is one with the spacebar:

    Code:
    tell application "iTunes"
    	activate
    	tell application "System Events" to key code 49
    end tell
    This would activate iTunes, and send the spacebar to start the current selected tracks.

    You would need to get the key codes for the various keys, there are a few apps out there that do this. Just search "key codes mac."

    Hope that helps.
     
  3. dikketienes thread starter macrumors member

    Joined:
    Oct 13, 2008
    #3
    Yeah thanks,

    Exactly what I was looking for, and great examples.

    Greets Dick
     

Share This Page