I was making a menu option and needed a value to switch on and off with each run.
This little experiment just gave me a laugh so I thought I’d share it.
Each run returns the opposite of the previous run.
Enjoy!
property tf : true
set tf to not tf and not tf is not tf
return tf
Here is an example of using an “in-menu-toggle” to swap to an alternate list.
------------------------DEMO CHOOSER MENU with toggled alternate list------------------
property tf : true
repeat
---TRUE---
if tf then set {swtch, lst, ttl} to {"Use text instead?", {1, 2, 3}, "number-mode"}
---FALSE---
if not tf then set {swtch, lst, ttl} to {"Use numbers instead?", {"one", "two", "three"}, "text-mode"}
---MENU---
set chs to (choose from list ({swtch} & lst) with prompt "" with title ttl)
if chs contains swtch then
set tf to not tf and not tf is not tf ---> toggle tf's value!
else
return chs ---> exit the repeat loop!
end if
end repeat
And here is an example of using an “in-menu-toggle” to activate or deactivate a “dropdown-menu”.
------------------------DEMO CHOOSER MENU with toggled dropdown list------------------
property tf : false
repeat
---TRUE---
if tf then set {swtch, lst, ttl} to {"Hide Dropdown?", {tab & "Option1", tab & "Option2"} & {1, 2, 3}, "Dropdown Active"}
---FALSE---
if not tf then set {swtch, lst, ttl} to {"Show Dropdown?", {1, 2, 3}, "Dropdown Hidden"}
---MENU---
set chs to (choose from list ({swtch} & lst) with prompt "" with title ttl)
if chs contains swtch then
set tf to not tf and not tf is not tf ---> toggle tf's value!
else
return chs ---> exit the repeat loop!
end if
end repeat