Help!

Discussion in 'Mac Programming' started by PBLRDom, Apr 3, 2012.

  1. PBLRDom, Apr 3, 2012
    Last edited: Apr 3, 2012

    macrumors newbie

    Joined:
    Dec 22, 2011
    #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?
     
  2. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    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 :
     

    Attached Files:

  3. thread starter macrumors newbie

    Joined:
    Dec 22, 2011
    #3
    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.
     
  4. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    What do you mean by :

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

    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
     

Share This Page