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

PBLRDom

macrumors newbie
Original poster
Dec 22, 2011
25
1
I need to write a script that will execute some really basic stuff and I can't figure out how.

All i need is for my X key and my spacebar key to be pushed 2 times each every 5 minutes.
literally.... xx then two spacebar pushes
I would like the duration of the keystrokes to be 1 second long.

Is this possible?
 
Last edited:
In order for the "System Events" application to use the key code or keystroke commands, you have to enable Mac OS X's accessibility frameworks."System Events" will send a key code or a keystroke to the frontmost application.

Paste code in scripteditor :

Code:
tell application "System Events"
	repeat
		keystroke "x"
		keystroke "x"
		keystroke space
		keystroke space
		--change delay 10 to delay 300 for 5 minutes delay
		delay 10
	end repeat
end tell

Don't know if the duration of the keystrokes can be 1 second long.
Will result in this as the frontmost application is scripteditor :
 

Attachments

  • keycode01.png
    keycode01.png
    91.3 KB · Views: 81
  • Afbeelding 4.png
    Afbeelding 4.png
    65.6 KB · Views: 86
Ok that works awesome! TY!
Now how do i get it to run within an application?

----------

also how does the delay work/. i see that it says 5 mins, but it runs much faster. I want it to continually run until i turn it off.
 
What do you mean by :

Now how do i get it to run within an application?

Do you want to send your keystroke to some application? Please specify.

Also how does the delay work

I thought this line explains what you must change :
--change delay 10 to delay 300 for 5 minutes delay
Change delay 10 to delay 300 for a 5 minutes delay. Delay is in seconds so
60x5=300 seconds = 5 minutes.

The script will continue to run untill you click stop in scripteditor
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.