Using switch button

How do I reference a switch button? I tried this but I get a sytax error.

if switch button “ChkBox_1” is selected then
display dialog “Check box 1 is really checked.” buttons {“OK”} default button 1
end if

I think you’re looking for…

if state of button "ChkBox_1" is 1 then
display dialog "Check box 1 is really checked."
end if

…where 0 is not selected and 1 is selected. Most on/off buttons use the state property to reference their “selected” value. Likewise you can set their state using…

set state of button "ChkBox_1" to 0 --> The button is NOT checked

Make sure to reference the window and any other containers they’re inside of.


Thanks. I now have to ask where can I find out about this kind of thing? In other words, there must be a good reference out there but I don’t know what to look for or what I’m looking for.

I’ve learned everything I know about AS and ASS from a handful of places…some of them finite…some of them not so much so. :wink:

  1. Here at macscripter. There are a number of kind, skilled, and generous people here that will help fill in any gaps in the rest of the resources below. There are many parts of this site that are a wealth of information…providing code, example files, and random insights not found anywhere else. I disagree with some that the search feature is without some flaws, but you can generally find just about anything your looking for pretty quick…assuming it’s been covered in the forums before. :slight_smile:

  2. Apple Developer websites:

    • Applescript Studio Terminology Reference; Although not the most complete documentation they do have a separate web page for pretty much every applescript studio object, term, procedure, etc. I recommend using the search field, I usually type in my query and then include ‘applescript’ behind it so I get more relavent results. Something like “popup button applescript” usually returns exactly what I want.
    • Language guide; Details about the applescript language itself. Useful for figuring out the logic for your scripts.
  3. The applescript studio example projects. Found in “/Developer/Examples/Applescript Studio/”, they are far from perfect, but actual working implementations that often can give you a start.

  4. The INTERNET. Often a search at for whatever you’re looking for will yield many results that may interest you. It’s hard to find real life working code and examples/tutorials, but they are out there and can lead you to many goals if you spend the time finding them. Jon Nathan (jonn8) has a generous selection of source files and example code at his site, and there are others who have raw archives of code and projects that anyone can download. You’ll have to do some exploring to find your own favorite web resources.

  5. Books?! There are people who claim to still “read books”, but I prefer to strain my eyes, overwhelm my senses, find some unexpected side-tracks, and say up too late reading my monitor rather than one of those old-fashioned book thingies. 8)

Hope that gives you some leads.

Yup. Thanks for the leads. I’m balancing two scripting languages here. One end is JavaScript for Acrobat and the other Applescript. The JavaScript end is heavier right now. Thanks for the help. It is most appreciated.