Re: booleans...
Re: booleans...
- Subject: Re: booleans...
- From: Stan Cleveland <email@hidden>
- Date: Mon, 19 Mar 2018 22:25:51 -0700
On Mar 19, 2018, at 10:02 PM, Jean-Christophe Helary
<email@hidden> wrote:
>
> What I want, as I wrote earlier, is a way to coerce any statement to boolean
> values instead of having to add try block everywhere. Either a statement
> returns a value and it is true, or it returns an error (or nil) and it is
> false
Okay, this approach is a bit ugly, because requires your "any statement" to be
converted to a properly-escaped AS string, like so:
alias ("" & (path to desktop) & "not.there")
becomes:
"alias (\"\" & (path to desktop) & \"not.there\")"
Then, it uses run script to either convert that string to a valid AS result or
return false:
on myBoolean(myExpression)
try
set theResult to run script myExpression
on error
set theResult to false
end try
return theResult
end myBoolean
myBoolean("alias (\"\" & (path to desktop) & \"not.there\")")
--> false
myBoolean("alias (\"\" & (path to desktop) & \"is.there\")")
--> alias "MacHD:Users:stanc:Desktop:is.there"
myBoolean("\"hello\" as integer")
--> false
myBoolean("45.6 as integer")
--> 46
myBoolean("\"45.6\" as integer")
--> 46
As I said, it's ugly.
Stan C.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden