Applescript's inability to have *empty* variables?

Is applescript completely unable to have empty variables? By empty I mean…

set myVar to "false"

NOTE: That -^ is NOT meant to be a boolean, it’s meant to be a string variable that holds the word “true” or “false”. (Because applescript won’t let me have empty booleans either…)

So now, I’m forced to write my variables to hidden text files on disk, then re-read them later. Which is slow… and stupid. But anyway… if my variable does not represent something, like the contents of a text fbox applescript ALWAYS returns that the variable does not exist! WTF? It’s right there! It’s the word “false”! sigh

I CAN fix this problem. by writing all my variables to disk. Oh well, I’ll try that next.

Any help would be great, thanks!

Model: iBook
AppleScript: 1.10
Browser: Safari 412.5
Operating System: Mac OS X (10.4)

It sounds like you’re looking for ‘missing value’, as in :

set myVar to missing value
if myVar is equal to missing value then
	--do something
	--do something else
end if

BTW, your example works fine for me

set myVar to "false"
return myVar
--result "false"

So perhaps I didn’t, and don’t, understand the question

Hmm but wait… I see the light! YAY! You have made it all clear to me! Thanks so much!

Unfortunatly, the solution you led me to “conceive” did not work. :frowning:

Here is a “sample” of what I’m trying to do.

Early up in the code a shell script returns a “true” or “false”, as a “echoed” string.

set myTest to do shell script "/.myTestsH"


if myTest is "true" then
	-- do nothing
	set myTestFailed to "true"
end if

And later on.

if myTestFailed is "true" then
	display dialog "The test failed!"
end if

What’s wrong with that? Wouldn’t it work? (Assuming you have the script I wrote installed!)


This works for me:

set myVar to "false" as boolean

if myVar then
	beep 3
end if

Doesn’t that do what you want?

Does “myTestFailed” get created if “myTest” is true? Have you tried this?

if myTest is "true" then
	set myTestFailed to "false"
	set myTestFailed to "true"
end if

Also, is there a reason you can’t check “myTest” directly?

if myTest is "true" then
	display dialog "The test failed!"
end if

As a side note, if you really wanted to, you could coerce the shell script result to a boolean:

do shell script "/.myTestsH"
set myTest to result as boolean

-- .something else?

if myTest is false then display dialog "The test failed!"

It only does anything if it failed, it if passed, then it’s to be ignored, otherwise I’d need even more variables, but fear not. It will no longer have a failed/passed checker.

Instead it will plough on trying to do the impossible until all system resources are consumed and the computer crashes, resulting in data loss.

Hmm now I’m solving problems like Bill Gates! I’ll be rich in no time!

But what if the result, was say “Hello World!”

Then myTest would be false:

get "Hello World!" as boolean
-- result: false

However, you said:

.so it shouldn’t be a problem in this particular instance. If you shell script is supposed to return “true” or “false,” but is returning “Hello World!,” then you have other problems.

Your original question still doesn’t make any sense. According to the glossary.

So, typically, variables contain a value. If you want to represent an empty/missing/null value, then you can do this (as EliseVanLooij stated):

set something to missing value

Let’s check the glossary again:

In instances where a boolean is appropriate, these two values are all you need.

It’s not. It’s a string:

set myVar to "false"
return class of myVar
-- Result: string

Note that any string expect “true” (ignoring case), if coerced to a boolean value, will be false.

Wait, where did that come? What’s really going on here? Perhaps you should post your entire script (and shell script) here, so that the rest of us can follow along.