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

dikketienes

macrumors member
Original poster
Oct 13, 2008
64
0
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
 
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.
 
Yeah thanks,

Exactly what I was looking for, and great examples.

Greets Dick
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.