Is it possible to save a Variable with nothing in it? I have to put a space in it to get the variable to save which is okay but not my preference. I even tried %20 just to see if that would work and of course it saves %20 to the variable which is what I would expect it to do.
I also tried the %Delete% variable hoping that might work but of course that just removes the variable which is cool (sort of another alternative to Local with unnecessary steps added).
I am actually trying to write nothing from one macro to another so I don't have to write several other macros. I have tried a ton of Token's thanks to you hipping me up to them but nothing seems to work. It has to have at least a space to write to another variable other wise Keyboard Maestro just acts as though it doesn't exist and flashes an error message.
While I generally use local or instance variables, I often times have info I need to store in a variable for later on, but not indefinitely.
For instance, when a certain app launches on my computer, I have an AppleScript get the screen coordinates for it’s menu bar icon and set about a dozen variables accordingly (because the app is not scriptable directly), that way I can interface with it throughout the day. So I can’t use local or instance variables in that case because they would not be available later on when I needed them. But once that app quits, I set all those variables to %Delete% because I no longer need them and can’t stand clutter hahaha.
Any way you could post the macro you’re working on so we can take a look?
Okay so after further investigation I realized that it has to do with AppleScript not liking it to be empty. Perhaps there is no work around there. Keyboard Maestro displays the nothing text just fine.
For the record I realize what I wrote in this macro can easily be done all in Keyboard Maestro. I simplified this quite a bit because it actually linked to about 8 macros the outputs do different things in three different apps so I figured you didn't need to sort through that mess.
When I modify your script to the following, it runs fine.
tell application "Keyboard Maestro Engine"
set pomodoroKey to getvariable "pomSesAppKey"
end tell
--set pomodoroAction to pomodoroKey & " ()" & pomodoroLocation
set pomodoroAction to pomodoroKey
Notice that I changed the following line
set pomodoroKey to value of variable "pomSesAppKey"
to this:
set pomodoroKey to getvariable "pomSesAppKey"
And when I use that script in your macro it runs fine. Try this version below.
Empty - Example For Empty Variable to Delete Macro (v9.2)
I couldn't tell you to be honest. I hand't actually seen your way of retrieving a Keyboard Maestro variable in AppleScript before today. Perhaps some of the folks who are more knowledgeable in AppleScript can chime in... @ccstone?
Well I will be using your method from now on unless someone states a reason otherwise. I'll put that one away in the book of AppleScript/Keyboard Maestro code.
Thanks, I appreciate the link, that was my bad and just some code I had been using for over five years to get Variables in AppleScript and had not run into an issue until now. I should have looked there when I found that AppleScript was having an error. It is still curious to me but very glad it is working without the space.
Very strange that my earlier code worked fine for you, @cdthomer code made it work for me.
Understandable. I do things that are technically out-of-date and not the "right" way because it's what I picked up years ago and never saw the need to change since they still work haha.
For what it is worth I had t to change a few of these back in some of the AppleScripts since I started getting different errors. I will post a link to all the macros when completed for anyone that is interested.
tell application "Keyboard Maestro Engine"
--set pomodoroEvent to getvariable variable "pomSesCatAppKeyIntDurLoc" -Errors out.
set pomodoroEvent to value of variable "pomSesCatAppKeyIntDurLoc"
-- set pomodoroCatKeyInt to getvariable variable "pomSesAppCatKeyInt" --Errors out.
set pomodoroCatKeyInt to value of variable "pomSesAppCatKeyInt" --
set pomodoroDuration to getvariable "pomSesApp__Duration" --The reason why it has the two underscores is so we can display the name "Duration" only but that unfortunately has to save to a globlal variable with the two underscores as well in Keyboard Maestro. See "How to Hide a Variable Prefix in the Prompt" https://wiki.keyboardmaestro.com/action/Prompt_for_User_Input
end tell
tell front document of application "OmniFocus"
set theTask to make new inbox task with properties {name:pomodoroEvent, note:pomodoroCatKeyInt, estimated minutes:pomodoroDuration}
end tell
Then run the AppleScript from the Script Editor or Script Debugger.
tell application "Keyboard Maestro Engine"
set asTestVar01 to value of variable "testVar01" -- No good without space
set asTestVar02 to getvariable "testVar01" -- Works without space
end tell
I'd expect the value of method to work and return an empty string just as the getvariable method does, but it will throw an error.
On the other hand this works with either of the variable creation methods even though the make new command creates it without a value.
tell application "Keyboard Maestro Engine"
# Create Variable with:
make new variable with properties {name:"testVar01"}
# OR
setvariable "testVar01" to ""
set asTestVar01 to value of variable "testVar01" -- No good without space
set asTestVar02 to getvariable "testVar01" -- Works without space
end tell