RE: loaded script subroutines
RE: loaded script subroutines
- Subject: RE: loaded script subroutines
- From: "Wallace, William" <email@hidden>
- Date: Wed, 14 Jan 2004 11:21:03 -0600
- Thread-topic: loaded script subroutines
actually, what I discovered is that this does work:
--Main script
global scriptVar1, scriptVar2, theData
set scriptVar1 to load script "path:to:script1"
set scriptVar2 to load script "path:to:script2"
set theData to "My job sucks!"
tell scriptVar1 to doStuff(theData)
set theData to "I Rock!"
subHand(theData)
onsubHand(theString)
tell scriptVar1 to doStuff(theString)
end subHand
--Script1
on doStuff(myData)
display dialog myData
tell my scriptVar2 to doMoreStuff(myData)
end doStuff
--Script2
on doMoreStuff(myArgs)
set myString to myArgs & " and so do you!"
display dialog myString
end doMoreStuff
As before, the main script is saved as an application and script1 and script2 are saved as compiled scripts. the only differences are that in script1 the "my" keyword precedes the call to script2's subroutine, and also I've added a subroutine coded into the main script which calls Script1's routine again (which then in turn call script2's routine). In this simple example it all works exactly as I'd expect, but in my real script it still doesn't work (only now I'm getting primarily -1708 "<variable name> doesn't understand the <subroutine name> message" errors). I know it must have something to do with scope or context, but I can't seem to pin it down. If anyone has some insight into this type of modular AppleScripting (if, for instance, you've gone through exactly what I'm going through right now), or knows of a very informative article or tutorial somewhere (I've seen Bill Cheeseman's site and his article about script servers - that was, in part, the inspiration for this entire project), I'd really appreciate a hint or suggestion. I've more than doubled my intake of caffeine and nicotine over this one and I fear I may soon go nova if a solution doesn't turn up.
Anyway,
Thanks
B!ll
>
----------
>
From: email@hidden on behalf of Michael Grant
>
Sent: Tuesday, January 13, 2004 4:49 PM
>
To: AppleScript-Users list
>
Subject: Re: loaded script subroutines
>
>
On Jan 13, 2004, at 3:47 PM, Wallace, William wrote:
>
>
> --begin main script
>
> set scriptVar1 to load script "path:to:script1"
>
> set scriptVar2 to load script "path:to:script2"
>
> set theData "some string or something"
>
>
>
> tell scriptVar1 to doStuff(theData)
>
> --end main script
>
>
>
> --Script1
>
> on doStuff(myData)
>
> display dialog myData giving up after 10
>
> tell scriptvar2 to doMoreStuff(myData)
>
> end doStuff
>
> --end script1
>
>
>
> --Script2
>
> onDoMoreStuff(myArgs)
>
> set myString to myArgs & " meaningless"
>
> display dialog myString
>
> end doMoreStuff
>
>
>
> Now, if I saved the Main script as an application and saved script1
>
> and script2 both as compiled scripts (assuming that path:to: was a
>
> real location where the scripts were saved to) and then ran the main
>
> script app, I would expect to first see a dialog box with the text
>
> "some string or something", and then a dialog box with the text "some
>
> string or something meaningless". But it don't seem to work that way.
>
> What am I doing wrong?
>
>
Besides leaving out the 'to' when setting the variable theData, you
>
never told your script 1 about script 2. You either need to pass the
>
variable scriptvar2 along with theData, or load script 2 within script
>
1.
>
>
Michael
>
>
--
>
I believe there's something out there watching over us. Unfortunately,
>
it's the government.
>
>
- Woody Allen
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.