I figured I could use a Try/On Error to set the accessKeyId value and if it was not present it would error, I would know they are unauthenticated, and I would have them authenticate:
try
set accessKey to accessKeyId of accessInfo
on error
run authenticate handler here
end try
But it is throwing an AppleScript Execution Error instead of going into the On Error.
Yes, although it’s not so much a way around, as it is the way to do it. Whenever someone uses try in AppleScript, that is them employing a way around something that will have a more elegant (and robust) method lurking around somewhere.
Regarding records in AppleScript, consider the joining of these two records:
{a : 1, b : "two", d : 4.0} & {b : [2], c : pi, d : 2 ^ 2}
They both have property identifiers in common as well as one each that is unique to them. The resulting record will, of course, contain one copy of each unqiuely named property, so the clue to solving your problem is to observe which value ends up being assigned to the properties of the merged record with identifiers common to both original records?
When you determine that, then to prevent an error from being thrown, jusy ensure that:
set accessKey to accessKeyId of accessInfo
accessInfo definitely has a property identified by accessKeyId, even if it doesn’t come with one originally, whilst also ensuring that, any attempt to insert new properties into the record wouldn’t run the risk of overwriting a pre-existing entry were one to be present.
Thanks. They aren’t two records being returned no merging being done. Found that I could just use a get within the try and it avoids the execution error:
try
set accessKey to get accessKeyId of accessInfo
on error
set message to get message of accessInfo
I know… You were supposed to do some thinking of your own to see how my guidance could be applied to your problem. Anyway, the idea is that you merge the record from which you wish to extract a given property, with a record of your own creation that contains default values for this property:
set accessKey to (accessInfo & {accessKeyId:false})'s accessKeyId
If accessInfo contains the property accessKeyId , then its value will be assigned to your variable; otherwise, the value false is assigned.