Re: Stumped - How to call subscript?
Re: Stumped - How to call subscript?
- Subject: Re: Stumped - How to call subscript?
- From: has <email@hidden>
- Date: Wed, 17 Jul 2002 21:48:56 +0100
Dan Feather wrote:
>
I've got a script which has a number of stored properties, and I'd like
>
to be able to run another script which would, essentially, "erase" the
>
first scripts "memory" of stored properties. Therefore, the next time the
>
first script did its thing (it's a Folder Action Script), its properties
>
(the ones which are file-pointers) would be "" and thus the user would be
>
prompted to choose them again.
From your examples it looks like you've gotten yourself pretty confused
over how things like "run script" and script objects work. That last
example was particularly bizarre - I can't see how it'd possibly work (you
certainly can't "turn script objects into handlers", and if it did achieve
the desired results then it wasn't by any logical means).
Since I'm a little vague on folder action scripts [i.e. too lazy to RTFM],
here's a simple demonstration of the approach you'd use if the main script
was saved as an applet [note that applets automatically store their latest
state every time they quit].
======================================================================
--main script (save as applet and run it a few times)
property myState : ""
on run
if myState is "" then
display dialog "Enter your name:" default answer "Bob"
set myState to text returned of result
else
display dialog "Hello, " & myState
end if
end run
on resetSelf()
set myState to ""
end resetSelf
======================================================================
The 'resetSelf()' handler [or whatever else you want to name it] simply
contains whatever code I need to 'reset' the values of the script's
properties.
You'd then run the following script any time you want to reset the main script:
======================================================================
tell application "main script"
launch
resetSelf()
end tell
======================================================================
Once you've done that, the next time you run the applet it'll prompt you to
enter your name again.
With regular compiled scripts, you can't access the state of the script
object on disk. You can execute it using "run script", or load it using
"load script", but both will create a _copy_ of the original script object
and changes made to that object won't be reflected in the original file on
disk. You need to load the script object from disk, do whatever you're
going to do [in this case, tell the object to resetSelf()] and then _store
it back_ to disk, replacing the original file:
======================================================================
--helper script
property pathToMainScript : alias "[Your Path Here]"
on resetMainScript()
set mainScript to load script pathToMainScript
tell mainScript to resetSelf()
store script mainScript in pathToMainScript replacing yes
end resetMainScript
resetMainScript()
======================================================================
So you weren't a million miles off in your last attempt [load, modify,
save], but that stuff with "tell [script object] to [script object]" was
just too weird.
Hopefully you can work out how to apply this approach to your folder action
scripts. You are then welcome to come back and give _me_ a lesson in how to
use the darn things...;)
HTH
has
--
http://www.barple.connectfree.co.uk/ -- The Little Page of Beta AppleScripts
_______________________________________________
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.