Problem
Apparently with the security changes made in Mojave and now going forward, I lost the ability to store globals between invocations of my scripts.
All that I want to do is to toggle states of connections based on my location (e.g. work versus home toggles ethernet versus WiFi and other stuff). I want to store the state for the next time so that I can know what the setting had been.
I don't do XCode development (I do however program in other languages such as python). Everything for AppleScript is in ScriptEditor (perhaps soon Script Debugger instead). Finally, I am conversant enough to know how to write the scripts and save them as applications. Anything else that I need to use would hopefully be at a "plug-and-play" level of effort.
Example Script
Here is an example of a script that I use to toggle the status between presentations and no presentations. In this, pCurrentMode is no longer being maintained between invocations. Under High Sierra, it ran with no problems. Under Mojave, it does not remember the previous invocation state. I have a few other equivalent scripts that do the same. They are saved as .app files in the Scripts folder (for menu access whenever I need them).
property pAppsToToggleOFF : {"Mail", "Safari"}
property pAppsToToggleinMSB : {"EasyMP Network Projection"}
property pAppsToToggleinTeach : {"AirServer", "Panopto"}
property blueutil : "/usr/local/bin/blueutil"
property pCurrentMode : "Off"
on run {}
-- ask how to set
set whichMode to choose from list {"Teach", "MSB Show", "Off"} with prompt "How?" default items pCurrentMode
if result is false then return
if (whichMode is equal to pCurrentMode) then return
set pCurrentMode to whichMode as text
set inTeachMode to (whichMode as text is equal to "Teach")
set inMSBMode to (whichMode as text is equal to "MSB Show")
set inONMode to (inTeachMode or inMSBMode)
set inOFFMode to (whichMode as text is equal to "Off")
if (inONMode) then
-- start presentation mode
if (inTeachMode) then
repeat with apptoToggle in pAppsToToggleinTeach
try
tell application apptoToggle to activate
end try
end repeat
else if (inMSBMode) then
repeat with apptoToggle in pAppsToToggleinMSB
try
tell application apptoToggle to activate
end try
end repeat
end if
repeat with apptoToggle in pAppsToToggleOFF
try
tell application apptoToggle to quit
end try
end repeat
-- switch to WiFi and turn off bluetooth
do shell script "scselect WiFi"
do shell script blueutil & " off"
else if (inOFFMode) then
-- end presentation modes
repeat with apptoToggle in pAppsToToggleinTeach
try
tell application apptoToggle to quit
end try
end repeat
repeat with apptoToggle in pAppsToToggleinMSB
try
tell application apptoToggle to quit
end try
end repeat
-- switch to ethernet and turn on bluetooth
do shell script "scselect Ethernet"
do shell script blueutil & " on"
end if
-- show or hide the dock and desktop icons
hidetheDock(inONMode)
showDesktopIcons(not inONMode)
end run
on showDesktopIcons(state)
set theCmd to "defaults write com.apple.finder CreateDesktop " & state & "&& killall Finder"
do shell script theCmd
end showDesktopIcons
on hidetheDock(state)
tell application "System Events" to set the autohide of dock preferences to state
end hidetheDock
A Concluding General Question
By way of reference, when I started looking for insights on how to solve this problem, as a beginner/intermediate user of AppleScript, I was lost about where I should go for the most recent information to figure out why this was now happening. This prompts me to ask a follow up based on a question from two years ago posted at this link.
In a nutshell, where do programmers go to find resources about the newest practices to write robust scripts with AppleScript?
I stumbled across the site for Script Debugger while subsequently looking for "applescript globals". The site offered some insights. I would be hard pressed to read all of the forum posts to cull the information that I need laid out in a tutorial + example manner. But if this is the current practice, so be it.