I just started playing with AppleScript Studio, so bear with me…
I have a test project that returns text into a text field that works just fine when I’m using buttons. But I want to use “Tabs” instead of buttons, and I can’t figure out a way to get it to work. Here’s the script code that works for “Buttons”, but not for “Tabs”…
on clicked theObject
if (name of theObject is "t1") then
set contents of text field "tf1" of window main to do shell script "ls"
if (name of theObject is "t2") then
set contents of text field "tf2" of window main to do shell script "cd ~;ls"
Is “on clicked theObject” the correct syntax for “Tabs”?
At first glance I see two things that stand out. First you have and if statement nested within another if statement and I think you would be better off with an if/else if type statement.
Second I would guess that you have named (or should have named) your window “main” and therefore should have quotes around the word “main”.
Lastly, if I understand you correctly, you want the if statement evaluated when you switch between tabs. If so, I think that on clicked is not available for tabs. Check out the applescript info panel for the tab object (first click, subsequent clicks drill down to the individual tabs) and look for event handlers connected to the Tab View.
I hope that helps. Let me know if you need more clarification or if I am off track.
Thanks for the help, here’s what I finally came up with…
on awake from nib theObject
set contents of text field "tf1" of tab view item "t1" of tab view "tabs" of window "main" to (do shell script "ls -al")
set contents of text field "tf2" of tab view item "t2" of tab view "tabs" of window "main" to (do shell script "cd / ;ls")
end awake from nib
I didn’t really need the “if” clause, and I replaced the “on clicked” handler with an “awake from nib” handler.