If Variable Exists using clipboard

This AppleScript checks if there is an existing variable with the name matching the clipboard

tell application "Keyboard Maestro Engine"
	set q to the clipboard
	if not (exists variable q) then
		return 0
	end if
end tell

Can this be done without AppleScript? (Note that I want to know if the variable exists, not if it is empty.)

Can't seem to use the %SystemClipboard% token here

Maybe a technique for processing the token? I also tried a text condition, but there is no "exists" option there.


I think you may be using some terms in ways which are unclear to me

"the name matching the clipboard"

Are you testing for a condition in which the string contents of the clipboard corresponds to:

  • the name of a particular variable ?
  • the value of a variable with a particular name ?

Hey that was a kind way of pointing that out :slight_smile:

The name of a particular variable.

I copy the text "var1" and want to know if there is an existing variable named "var1"

Thanks, I was being slow – an example always seems to prove clearer than a description :slight_smile:

My understanding of this field:

with its V rather than T at far right, and its red ink as soon as we enter a % is that it's not equipped to expand text tokens.

Others may know of other routes, but I can personally only see scripted solutions.