AppleScript novice needs help

Discussion in 'Mac Programming' started by jonat8, Jan 25, 2005.

  1. macrumors regular

    Joined:
    Dec 17, 2004
    Location:
    United Kingdom
    #1
    Hi,

    I've decided to learn a bit more about AppleScript and am using the latest xcode to make an AppleScript application to talk to iTunes.

    I have 3 text fields on a blank form, and 2 command buttons. The basic idea is that you type the user playlist name and track number in and click the first command buttons and the program queries iTunes for the name of the track.

    That bit works OK. But then the second command button tells iTunes to play the aforementioned track. This is where I'm having the problem.

    I have one AppleScript file - jonathan.applescript.

    The first "on clicked" section - on clicked ExecuteBNT has the code to take the inputs and retrieve the track name from iTunes. Once I typed that I typed in "end clicked" and then started another "on clicked" section - on clicked btnPlay and added my code to tell iTunes to play the track, ending with an "end clicked". This is all in the same one file.

    But when I Build, I get the error "The <<event soVSclil>> handler is specified more than once (-2752)".

    I can tell that for some reason it doesn't like more than one "on clicked" in one file, but can anyone help me on how to fix it?

    Thanks :)
    J.
     
  2. thread starter macrumors regular

    Joined:
    Dec 17, 2004
    Location:
    United Kingdom
    #2
    Oh here is the complete code from jonathan.applescript :)

    Code:
    on clicked ExecuteBNT
    	tell window of ExecuteBNT
    		set thePlaylist to contents of text field "playlistName"
    		set theTrackID to contents of text field "trackID"
    	end tell
    	
    	tell application "iTunes"
    		copy (get name of track theTrackID of user playlist thePlaylist) to trackName
    	end tell
    	
    	tell window of ExecuteBNT
    		
    		set contents of text field "trackNameField" to trackName
    		
    	end tell
    	
    	
    end clicked
    on clicked btnPlay
    
    
    	tell application "iTunes"
    		play track theTrackID of user playlist thePlaylist
    		
    	end tell
    	
    	
    end clicked
    xcode puts the error next to the line "on clicked btnPlay"
     
  3. thread starter macrumors regular

    Joined:
    Dec 17, 2004
    Location:
    United Kingdom
    #3
    I fixed it after some nosing around the sample apps and online :D
    Thanks anyway :)

    Code:
    global thePlaylist
    global theTrackID
    on clicked theObject
    	
    	if name of theObject is "ExecuteBNT" then
    		
    		tell window of theObject
    			set thePlaylist to contents of text field "playlistName"
    			set theTrackID to contents of text field "trackID"
    		end tell
    		
    		tell application "iTunes"
    			copy (get name of track theTrackID of user playlist thePlaylist) to trackName
    		end tell
    		
    		tell window of theObject
    			
    			set contents of text field "trackNameField" to trackName
    		end tell
    		
    	else if name of theObject is "btnPlay" then
    		tell application "iTunes"
    			play track theTrackID of user playlist thePlaylist
    			
    		end tell
    		
    	end if
    	
    	
    	
    	
    end clicked
     

Share This Page