I used to use this AppleScript for incrementing a counter every time I was running the script, I tried to use again (from Keyboard maestro now) but the value remain to "1" no matter how many time I'm running it.
Any idea how can I fix it? I assume KM is recompiling every time I'm running which is causing the issue (I'm probably wrong though)
property today : missing value
property currentCount : 0
increment()
on increment()
set currentDate to short date string of (current date)
if currentDate is not today then
set today to currentDate
set currentCount to 0
end if
set currentCount to currentCount + 1
end increment
Here a new demo code (I can't seems to compile your example somehow).
property today : missing value
property currentCount : 0
increment()
on increment()
set currentDate to short date string of (current date)
if currentDate is not today then
set today to currentDate
set currentCount to 0
end if
set currentCount to currentCount + 1
end increment
set myResolution to {"Demo", "Demo2"}
set selectedResolution to choose from list ¬
myResolution with title "Resolution - [Case count " & currentCount & " ]" with prompt ¬
"What's your resolution?" default items "Demo"
You need to switch the setting at the left of the Execute Applescript action to Execute Script File, and point it at a .scpt file at a specific location.
The persistent memory can only be held in a compiled .scpt file.
There's no location for it in a text held in KM's plist.
It compiles fine for me on macOS 10.12.6 Sierra...
What you're missing here is that Keyboard Maestro runs AppleScript using osascript and what that means.
It means that when you run a text script a new instance of AppleScript is created, the script run, the result (if any) returned, and the instance then disappears into the ether.
There is NO POSSIBILITY of persistence, because nothing at all remains.
What @ComplexPoint is telling you when recommending running from a script file, is that property persistence is ACHIEVED then because and only because osascript runs the script FILE as input and then rewrites that same file on completion.
That's how and where persistent properties are saved.
If you want to run a counter like this in an AppleScript text script then you have to save your persistent properties OUTSIDE of AppleScript.
You can do that by saving to a Keyboard Maestro variable or to a file on disk.