AppleScript Studio help

Discussion in 'Mac Programming' started by Keytachi, May 10, 2008.

  1. Keytachi macrumors regular

    Joined:
    Sep 14, 2006
    #1
    hi everyone! i started to take my first steps on ASS, after doing some lousy apps on AS :)P), and i need some help.
    My goal is to make an application that, when i press the button "start" it starts a loop. when i press the button "stop" it stops the loop.

    this is what i got so far (i took the "if ChosenButton..." from here
    Code:
    on clicked theObject
    	set ChosenButton to the name of theObject
    	if ChosenButton is {"Start"} then
    		repeat
    			tell window of theObject
    				tell application "System Events"
    					tell application "TextEdit" to activate
    					keystroke " "
    					delay 10
    				end tell
    			end tell
    		end repeat
    	end if
    	if ChosenButton is {"Stop"} then
    		exit repeat
    	end if
    end clicked
    
    but with this script, i get a -1708 error :(
    i had something different (on idle handler and a variable that only started the on idle if i pressed the start button, but i was never able to make it stop the loop).

    Anyone has any ideas?

    Thanks, Keytachi


    P.S.
    For testing purposes i'm using TextEdit and "a"
    and yes, i do have assistive devices allowed
     
  2. lancestraz macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #2
    Try this. Make sure to set the variable x to TRUE when your program launches.
    Code:
    on clicked theObject
    	set ChosenButton to the name of theObject
    	if ChosenButton is {"Start"} then
    		repeat while x is true
    			tell window of theObject
    				tell application "System Events"
    					tell application "TextEdit" to activate
    					keystroke " "
    					delay 10
    				end tell
    			end tell
    		end repeat
    	end if
    	if ChosenButton is {"Stop"} then
    		set x to false
    	end if
    end clicked
     

Share This Page