hi, i’m trying to make two apps(SB & IND) into one with the help of tabs.
I have 2 .applescript files, and I have 1 window “Main” and 2 tabs(SelfBoot & INDY) in my project. Each tab is supposed to represent its individual .ascript file, there are about 3-4 buttons and few text fields for both of the tabs.
(The text fields are output only,not input)
Here is method I used for my single window apps (no tabs) to get the status of button clicks:
on clicked theObject
if the name of theObject is "b_1st" then
--do stuff
end if
end clicked
Here is the one for returning text to the window:
tell window "Main"
set contents of text field "tf_name" to (fold_e as text)
end tell
How do I convert this code to use the afforementioned tab names?
You didn’t mention anything about the tab view itself. It too has a name and it must be set to have any of this work. We’ll assume here that it is named “MYTABS”, so change any instances of that below to your tab view’s real AS name. I’ve selected “INDY” to use in my examples…you can change that as necessary in your code to any other tab view item’s name.
Item 1…
This one should still work fine. Since this is a clicked event, the scripts don’t need to know WHERE the button lives to evaluate it’s object name (its APPLESCRIPT name, not it’s title). A button’s object name is the same whether it is in a tab, in a window, etc. and is sent as part of the click. Just make sure you have it’s on clicked event handler pointed at the script with your code in it.
Item 2…
For this one, try something like…
tell window "Main"
set contents of text field "tf_name" of tab view item "INDY" of tab view "MYTABS" of window "Main" to (fold_e as text)
end tell
This assumes that “fold_e” is a variable you’ve already declared somewhere else
About returning the text to the text field, I have a Q.
In the get info window> Applescript for the ‘Main’ window, it gives you the option to connect it to ‘Scripts’ (in my case SB.as & INDY.as). It will only let me connect the main window to one of the scripts, and have text fields in both tabs (and in both .as scripts). Am i missing something?
Yes, it is simpler than it seems… at first. Unfortunately, the more you know the bigger bites you take, and the harder it gets.
You don’t need to connect the “Main” window to any particular script to have it be able to ‘receive’ information from your scripts. You can set the content/attributes of any object in any window via any applescript in your project…assuming you code the script correctly. You can have a.script, b.script, and c.script all tell window “Main” what to do, and you don’t need to connect “Main” to ANY of them to do this. I don’t connect windows to anything unless I have a specific reason to do so (see below). Just use the appropriate script code to tell a particular text field what it’s content should be and your will shall be done .
You only need to connect a window to a script if you want it to invoke a handler in one of your scripts when the window ITSELF does something. You do not need to connect a window to enable the window’s contents to access scripts. Each object’s connection to a script relies solely on it’s configuration in the applescript pane of the info window, and is independent of the settings of it’s window, generally speaking. You’ve probably seen the events that can trigger a window to call a script. Basically any time a user opens/closes/changes a window (the actual window, not it’s contents) you can do the same things you could do if you had used a button. I can PM you with more info if you are unclear about this or want examples of how I make good use of connecting window events to scripts.