Hello all,
I’m squeaky green brand spankin’ new here, so please go easy on me. I’ve searched, I’ve thought, I’ve noodled, I’ve tested all to no avail. I can’t find my answer so I’m asking. Note: This question is for a project due MONDAY - a real live double clickable tiny little app that does something. Help! Also, forgive me if this is long…I’m trying to be thorough.
I have a little app. I’ve built it and it works, and I’m trying to make an advancement. The little app presents a user with a window with some buttons. Each button is a toggle, and it sends an apple event to an application running on another machine when the user clicks the first time(i.e. toggles it on), then sends a different apple event to an application running on another machine when they click the button again(i.e. toggles it back off). That much of my app is working fabulously.
Here’s the problem: I have the “target” machine hard coded in the script for each button, and now I want to go back and take that hard declaration out and use a variable I can edit once. Someday I’ll turn that one reusable variable containing the “eppc://blah.blah.blah.local” target into a spiffy text entry field for the user, but not now. I don’t mind changing it in ONE place and rebuilding the app.
I believe I need to declare a property somewhere like <property targetMac : “eppc://blah.blah.blah.local”>, and I’ve done exactly that. I put that in a scriptlet called “start”, and have tried attaching to all sorts of things: the only window that opens (at launch), the various application event handlers, et cetera. I’ve even followed the property delcaration wtih a little dialog box to read it back to me after it’s set.
It seems that I can never get that property as a variable in any other script. I click on a button, and the script that should be getting it’s "“eppc://blah.blah.blah.local” string from the property I called out always errors with “the variable targetMac is not defined”.
What I DO know: A property is a variable that isn’t disposed of when a script ends, and a variable is gone at the end of the script it’s created in. So, a property is what I want here yes? Create the property in some sort of startup script, and every other script (the ones attached to the 26 buttons…) can use it, right? It seems not.
What I DON’T know (too much to list here really…): I’m not sure exactly what script runs first, how I make sure the script that runs first doesn’t somehow end and throw away all it’s properties (which is what it seems like is going on), and make it so for now I can change this property in one place to glue this application to a specific remote machine as a target to send it’s remote apple events to.
I’m painfully aware that I could probably do the whole thing without single scripts for every button and all that, but my skill set is so low and so new with this sort of endeavor this way works for me. And I did manage to get a program I can put in front of someone and they can click away and the results of their clicks are exactly as expected.
Call for the question: If there’s multiple scripts using a variable, what script should set up a property and what event should it be handled by? Moreover, is it even possible and should I give up on the idea until I learn how to boil the 26 control buttons in one window to a single script?
Thanks in advance for your help and patience, and following is some of the stuff from my xCode project and the scripts.
Here’s one of my button scripts that works great(ignore the “event” stuff…it’s very specific to the product I’m talking to):
on clicked theObject
-- the state you're after is the state POST click...
-- toggles start at 0, go to 1, go back to zero
if state of theObject is 1 then ¬
tell application "Visionary 3D" of machine "eppc://G5-2x2g-Office.local"
Event "recall macro 602"
end tell
if state of theObject is 0 then ¬
tell application "Visionary 3D" of machine "eppc://G5-2x2g-Office.local"
Event "recall macro 642"
end tell
end clicked
Here’s what I want it to look like:
on clicked theObject
-- targetMac was set in start.applescript in a galaxy far far away...
-- the state you're after is the state POST click...
-- buttons start at 0, go to 1, go back to zero
if state of theObject is 1 then ¬
tell application "Visionary 3D" of machine targetMac
event "recall macro 601"
end tell
if state of theObject is 0 then ¬
tell application "Visionary 3D" of machine targetMac
event "recall macro 641"
end tell
-- set visible of theObject to false (maybe hide the used button someday?)
end clicked
Lather, rinse, repeat for 26 buttons.
Here’s the start script I can’t figure out where to attach, or how to ensure it’s always there supplying it’s property to the worker bee scripts. You can see me goofing around with what event should handle it:
property targetMac : "eppc://G5-2x2g-Office.local"
(*
on opened theObject
display dialog "your target machine is called " & targetMac buttons {"Thanks"} default button 1
end opened
*)
on will finish launching theObject -- just to check...
display dialog "your target machine is called " & targetMac buttons {"Thanks"} default button 1
end will finish launching
Thanks for reading,
WM
Model: various
AppleScript: whatever Xcode 2.1.1 uses
Browser: Safari 417.8
Operating System: Mac OS X (10.4)