Saving a property after running a script remotely
Saving a property after running a script remotely
- Subject: Saving a property after running a script remotely
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 10 Sep 2002 20:20:52 -0700
I have discovered that it's very difficult to save a property in a script
being run by another script. I wonder if anyone knows a good, reliable
method. Here's my set-up:
The Main Script is a Compiled Script currently being run from the Jaguar
Script Menu. (I have discovered that long scripts there need to be of the
'data-fork' type or something happens to them and they get 'lost' after
running once - they won't run again and script editors can't open them 'the
script could not be found' - presumably they can't be saved to the resource
fork.)
The Trigger script is a short script sometimes run from the Entourage script
menu on a schedule.
I want to be able to run the main script either from the Script menu or from
the Trigger script.
At the end of the Main Script's run, it resets its only property 'lastRun'
to (current date). There's no problem when it's run only from the Script
Menu.
Originally, I had the Trigger script do this:
set mainScript to load script alias mainScriptPath
tell mainScript to run
set mainScript's lastRun to (current date)
--store script mainScript in alias mainScriptPath replacing yes
To begin with, I didn't have the final line, but it became clear that the
property was not being set in the script file, just in the running instance.
But adding the final line made no difference. As far as I can make out,
after telling mainScript to run, since this doesn't expect a result it just
goes on to the next line, can't reset the lastRun property since the running
instance represented by the mainScript variable is busy running (but doesn't
error) , and perhaps saves the unaltered script-in-memory to file. Anyway,
it doesn't change the date in the lastRun property.
So I changed it to :
run script alias mainScriptPath
set mainScript to load script alias mainScriptPath
set mainScript's lastRun to (current date)
store script mainScript in alias mainScriptPath replacing yes
since 'run script' is supposed to have a result, but it made no difference.
Then I changed the main script so it really did return a result ((lastRun as
string)). Now I have:
set checkDate to run script alias mainScriptPath
set mainScript to load script alias mainScriptPath
set mainScript's lastRun to (current date)
store script mainScript in alias mainScriptPath replacing yes
Lo and behold, that saved the new date _sometimes_. But then I couldn't run
the Main script from the Script menu (the computer seemed to have exhausted
its memory - everything else was very slow). After rebooting everything was
OK, no 'lost scripts', but next time the script's lastRun reverted to an
earlier saved date before I started this 'run script' stuff. That's no good.
So - does anyone know a reliable way for the running Main Script to save its
own lastRun property - preferably from inside itself but stored from the
Trigger script would be OK too if reliable. If I have to, I guess I'll do
this as an applet instead, but it really is more convenient as a compiled
script in Script Menu. Is there a way?
OS 10.2 / AS 1.9.
--
Paul Berkowitz
_______________________________________________
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.