Applescript toggle to do This, this time, and That, next time? Let's say I have an Applescript that does THISCODE.  And I have another Applescript that does THATCODE.  I always run them in sequence, but never at regular intervals.  In other words, whichever one I ran last time, I'll always run the other the next time.

Is there a way to combine the two Applescripts into one using a simple toggle?  For example, at the end of the Applescript, could I write a variable into the beginning of the script that'll be read the next time, such as EVENvariable or ODDvariable...  so that, when the Applescript runs, it'll know which state it was in the last time it ran.  Or is there an even more simple and obvious solution I'm missing?
You can do it by setting your own defaults parameter, to store the value between uses/reboots etc, otherwise an Applescript will not remember your current toggled state.

This is a quick example that will set a user-defined parameter [replace with actual company &amp;/or product name &amp; memorable parameter name if you have one, otherwise the example data will do fine] then will just say out loud, 'yes' or 'no' depending on the state of the defaults parameter switch.

You can run it from the open script or save it as an application.

set newTestParameter to "YES"
try
    set oldTestParameter to do shell script "defaults read com.myCo.myApp myParamSet"
    if oldTestParameter is in {"1", "YES"} then
        set newTestParameter to "NO"
    end if
end try
do shell script "defaults write com.myCo.myApp myParamSet " &amp; newTestParameter

--your actual code, dependant on above switch
if newTestParameter is in {"1", "YES"} then
    say "Yes"
    -- run thisCode
else
    say "No"
    -- run thatCode
end if


On first run it will write a new file to ~/Library/Preferences called com.myCo.myApp.plist &amp; will contain one parameter, with the current state of your toggle, like this

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;myParamSet&lt;/key&gt;
    &lt;string&gt;NO&lt;/string&gt;
&lt;/dict&gt;
&lt;/plist&gt;


You don't need to do anything to 'maintain' this on your own, you can simply keep sending its new value with each script run.