Re: changing a script app's properties via another script
Re: changing a script app's properties via another script
- Subject: Re: changing a script app's properties via another script
- From: Arthur J Knapp <email@hidden>
- Date: Wed, 08 May 2002 17:35:54 -0400
>
Subject: changing a script app's properties via another script
>
From: email@hidden (Michael Sullivan)
>
Date: Wed, 8 May 2002 15:36:55 -0400
>
Can this be done?
Did you try to do it and it didn't work? ;-)
>
Basically, I'm looking to distribute a run only app which will have
>
certain properties hard compiled that I don't expect to change and don't
>
want the user to be able to access willy nilly.
>
>
But they might conceivably change. In which case, I'd like to be able
>
to distribute another applet which will do the change.
>
>
Basically, I want to access my original script as if it were a
>
scriptable application: open it, run one of it's handlers, then quit
>
it. But I *don't* want to run the run handler, only this other handler
>
which does nothing more than update the properties.
A call to a particular script application's handler will indeed just run
the handler and not "run" the script. A more explicit way to do this is
to use the "launch" command:
tell app "ScriptApp"
launch -- as opposed to activate or run
handlerOfScriptApp()
--
--> script apps do "remember" changes made, unlike merely compiled
-- scripts which you would have to use "store script" on.
You can also do a "load script/store script" procedure, though I admit
I'm not sure if "store script" does anything that might produce undesirable
results, (like maybe changing the file type to something other than APPL?).
A safer way to go here is to do what "real" applications do, use a
preferences file. You can either create your own file format, (which
can be difficult), or you can simply use a "store script" script object:
-- script application
script default_prefs
property pi_value : 3.14159
property sUsername : missing value
property sPassword : missing value
end
global user_prefs
on run
if ( [pref file exists in Preferences Folder] ) then
set user_prefs to load script [the pref file]
else -- ??? user threw it away ???
copy default_prefs to user_prefs --> copy, don't modify
[ask the user for their username and password]
set user_prefs's sUsername to [user's response]
set user_prefs's sPassword to [user's response]
store script user_prefs in [the pref file]
This would allow your "updater" to modify only the preferences file,
using "load script/store script". Of course, this carries problems of
it's own, such as when the user moves the script to a different machine
and forgets to copy over the prefs file. But then again, the "prefs"
file doesn't have to be in the Preferences Folder. Many applications
keep data files in the same folder as the application, and most users
would know to copy any associated data files around with the main
application. We can envision a typical setup:
folder "Amazing Script Folder"
application "Amazing Script" --> This knows to check for updates
file "Amazing Script Data" --> This gets updated by updater
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
(*) Happy
( ) Sad
( ) Ambivalent
( ) Ubiquitous
}
_______________________________________________
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.