Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a key in a record exists?

Tags:

applescript

I discovered that if I try to access a field in a record, e.g.:

set track_album to (|Album| of t)

And that field does not exist, AppleScript throws an error. How can I check if that field exists first? Or how to let it fail silently? (Whichever is the best practice.)

like image 787
Bill Avatar asked Jan 02 '10 22:01

Bill


1 Answers

set track_album to album of (t & {album:default})

it will be set to album if it exists or default if not.

or

try
album of t
on error -1728
default
end try
like image 73
jspcal Avatar answered Oct 17 '22 12:10

jspcal