Re: "Save changes to script" when it terminates?
Re: "Save changes to script" when it terminates?
- Subject: Re: "Save changes to script" when it terminates?
- From: Nigel Garvey <email@hidden>
- Date: Sat, 13 Mar 2004 10:29:09 +0000
Chap Harrison wrote on Fri, 12 Mar 2004 16:53:52 -0600:
>
On Mar 11, 2004, at 6:30 PM, Paul Berkowitz wrote:
>
>
>
> Your top-level variables, which are global by default and saved. If you
>
> explicitly declare them all as local at the top of the script, you
>
> should
>
> not have this problem.
>
>
>
>
Is there a way to declare variables so that they can be seen from a
>
handler, yet are not going to cause the script to try and save itself
>
after each run?
It depends on what you mean by "seen". For read-only access, you can, as
Paul suggested, declare all top-level variables as local then, as per
Michelle's advice, pass the relevant values as parameters to the handlers
that need to see them:
-- top of file --
local woof -- this woof is local to the script
set woof to (path to me as string)
foo(woof)
on foo(woof)
-- This woof is local to foo() but has been
-- passed the value of the script's woof
display dialog woof
end foo
-- end of file --
It might be more convenient to dispense with the top level of the script
altogether, except for a call to a subordinate handler that contains the
code you would otherwise have used at the top level. I've called the
handler main() here, following the C convention, but the term has no
significance in AppleScript:
-- top of file --
on main()
set woof to (path to me as string) -- this woof is local to main()
foo(woof)
end main
on foo(woof)
-- This woof is local to foo() but has been
-- passed the value of main()'s woof
display dialog woof
end foo
-- The only top-level instruction; no top-level variables set
main()
-- end of file
If you need global behaviour - where either it's inconvenient to keep
passing parameters or the handlers need to be able to change the values
of "top level" variables - you could put the entire working code of the
script into a script object in a handler. The "globals" would then have
to be properties of that script object:
-- top of file --
on main()
script myScript -- myScript is local to main()
property woof : (path to me as string)
-- Handlers
on foo()
display dialog woof
end foo
on bar()
set woof to (path to desktop as string)
end
-- "Top level" of myScript
foo()
bar()
foo()
end script
run myScript
end main
main()
-- end of file --
NG
_______________________________________________
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.