Pause Until Variable Is Not Empty (when variable is previously set to empty string)?

I see what you're saying, and that seems to prove it. The issue I have now is that my problem apparently lies somewhere else, which I still need to identify.

1 Like

Then I suggest you post your macros so we can better help you.

That's the plan. I just haven't had a chance yet.

Yes -- that's my bad. I've completely confused the issue by being completely wrong!

So the variable is deleted by setting it to the empty string, but the "label" remains in the Variables pane, and that displays the variable as containing nothing. As @tiffle and @Airy say, functionally there's rarely a difference between "deleted" and "empty" because as soon as you reference a "deleted" variable it springs to life, empty!

An example of when it does matter is in the thread you linked -- if you use AppleScript to access the variable directly:

tell application "Keyboard Maestro Engine"
	set value of variable "Global_a" to 1
	get value of variable "Global_a"
	(*1*)
	set value of variable "Global_a" to 2
	get value of variable "Global_a"
	(*2*)
	set value of variable "Global_a" to ""
	get value of variable "Global_a"
Result:
error "Keyboard Maestro Engine got an error: Can’t get variable \"Global_a\"." number -1728 from variable "Global_a"

...and you can see that you can set and get an existing variable, but as soon as you set it to an empty string it is no longer accessible (deleted) so the script errors. That's why it's suggested to use the getvariable verb -- it handles the empty/deleted variable case without erroring.

Ok. Thanks for the discussion y'all. I've been playing around with my macros this evening and that, plus the discussion in this thread, has convinced me that the issue doesn't lie with the way I'm using Pause Until.

I have some ideas on where I may be having issues, so I'm going to explore that more first before posting any further in this thread or, alternatively, start a new thread further down the road if/when I'm still not able to figure out the roadblock. I did manage to further isolate the problem this evening, so I'm hoping that I'll finally be able to identify the culprit soon.

Yes. I think I'm getting it now on how the subtleties of empty variables behave. Thanks for the example.

1 Like

As has been noted, the concept of whether a variable exists or not is not one which has a single answer, and so is generally not one you should ask.

For most practical purposes, a variable “exists” if it has a non-empty value, which is a question you can legitimately ask.

So going back to the original question, it is perfectly reasonable for a macro to Pause Until a variable is not empty.

2 Likes