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

crul

macrumors newbie
Original poster
Jul 29, 2012
3
0
(using xcode/applescript)
I have a window with a segmented control (with 2 buttons) and a push button. The push button is linked to this code:

Code:
property segment : missing value

on buttonPressed_(sender)
   log selectedSegment of segment
        
   if (selectedSegment of segment) = 1 then
      log "1"
   else
      log "0"
   end if
        
   log "---------"
end buttonPressed_

My problem is with the if statement. My log shows the following when the left button of the segmented control is active:

Code:
0
0
---------

and the following when the right button is active

Code:
1
0
---------

So it seems that 'log selectedSegment of segment' is returning the right value while the if statement doesn't work. Any idea what I'm doing wrong?

(I'm very new to xcode/applescript and just use it for some personal scripts, so please excuse me if this question is really nubish :p)
 
Last edited:

Mark FX

macrumors regular
Nov 18, 2011
159
17
West Sussex, UK
Try this code instead.

Code:
    on buttonPressed_(sender)
        log segment's selectedSegment()
        if (segment's selectedSegment()) = 1 then
            log "selectedSegment = 1"
        else
            log "selectedSegment = 0"
        end if
    end buttonPressed_

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