Global variable across two scripts

I have a windowless stay-open applet that has a line of code of this kind:

on idle
   If Todo_or_Not_todo then
      beep -- this of course is more complicated that just "beep"
   end if
end idle

The Todo_or_Not_todo is global boolean variable that I would like to change using a second script, which I can run anytime I want.

set  Todo_or_Not_todo to true -- or false

Is that possible? In other words is possible to share a single global variable between two different scripts?

When I need to do this, I just store the information in a text file on the computer and have each script read/write it as needed. I use JSON formatting for the files to keep it clear, but you can use whatever.

Using Dropbox or a shared drive or that sort of thing, you can share data not only between scripts, but between computers.

I agree that a text file is the best way to do this. An alternative might be to use a property in the first script and to modify it by way of a second script as in the following:

set myApplet to "/Users/peavine/"
set newValue to true
set scriptCopy to load script POSIX file myApplet
set scriptCopy's theProperty to newValue
store script scriptCopy in POSIX file myApplet with replacing

I’ve never done this with an stay-open applet and don’t know if it would work OK.

Thanks for the suggestions.
I was also considering the possibility to include in the APPLET, outside of the on idle / end idle code, several commands like those:

on setSendBooleanTrue()
	set SendBoolean to true
end setSendBooleanTrue

on setSendBooleanFalse()
	set SendBoolean to false
end setSendBooleanFalse

on SendBooleanStatus()
	return SendBooleanStatus
end SendBooleanStatus

Then I can trigger from the second script, by using

tell Application "my_APPLET" 
end tell

a bit like adding a custom dictionary to my APPLET. And thus let the APPLET do all the job.

Thanks anyway, I will check also your suggestions.


It’ll work with proper handler calls:

tell Application "my_APPLET" 
end tell

You are right.
Sorry for the mistake.
Thanks !