Ill start off and say I am a novice. I am having lots of problems with referencing to what I made in my nib file via the applescript code. What I have is a simple script that runs from the click of a button and I want that button to disappear and a new button (that i made in IB as hidden) to appear. I managed to get the original button called “Start” to disappear but i cant get the other button (Stop) to appear.
This is what I got so far:
on clicked theObject
if name of theObject is “Start” then
set Search to true
set stopHunt to false
set visible of theObject to false
set visible of button “Stop” of window of theObject to true – This Problem
–show button “Stop” of window of theObject – Area
end if
if name of theObject is “Stop” then
set stopHunt to true
end if
return true
end clicked
All works except it does not show Stop button, which I wrote in a thousand different ways to try to get it to work. Since I am trying to show the stop button within the other buttons action script do I need to connect them or something? I am at a loss. Any help would be greatly appreciated.
Using “window of theObject” can sometimes return the wrong results than those you’re looking for. Rather than doing this, why not just reference the window by name? You could query the window’s name of course, and then use that, but a better way would be to just hard-code the name in unless you have a great reason not to.
Also, you may be creating conflicts by using the “hidden” checkbox in IB’s info window. This is not effected by toggling the “visible” property. It seems to me that a hidden object remains hidden, despite what you set it’s visibility to. To get an object to be ‘hidden’ when it’s window becomes visible, attach a ‘will open’ handler to the window and then toggle the button’s visibility to false before the window is drawn.
on clicked theObject
if name of theObject is "Start" then
set theWindow to name of window of theObject
set visible of theObject to false
set visible of button "Stop" of window theWindow to true
-- OR --
set visible of theObject to false
set visible of button "Stop" of window "myWindow" to true
end if
end clicked
on will open theObject
set visible of button "Stop" of theObject to false
end will open
If I might suggest a cleaner option to your setup, you could dispense with the ‘stop’ button altogether, and just use one button… which I’ve called “Toggle”. Using the code below, check for the title of the button and set it according to the current status, and never worry about the visibility of anything.
on clicked theObject
if name of theObject is "Toggle" then
if title of theObject is "Start" then
set title of theObject to "Stop"
--> Your 'start' code here
else if title of theObject is "Stop" then
set title of theObject to "Start"
--> Your 'stop' code here
end if
end if
end clicked
Hey J, Sorry about posting in OS X forum, thought I did Applescript studio, my bad. Thanks though for your good explanation and tips. I learned a lot! And your last code snippet looks like something of what I was thinking but was not sure if you could change title names and use that as references. so I tried to keep my focus on more simpler methods. So yes thats a better idea and ill implement that later tonight. Ill post back here to let you know how it goes. Thanks again!