Records - Something weird is happening (read - I do not understand)

Hi all, am a relative newbie to AppleScript, but not programming. I am having trouble understanding why the following script does not work as expected …


-- Script Editor Version is 2.9
-- Applescript appears to be version 2.5
-- OSX Version 10.12.6
-- LNS Script Debugger version is 6.05

use framework "Foundation" -- useful for getting to objC structures 
use scripting additions -- Required if using "use" and shell scripts, and other scripting extensions

set theFile to "/Volumes/scratch/images/scripts/working_scripts/test_image2.JPG" as «class furl» -- fixes a bug in Applescript file handling - required when using "use"
set pathList to quoted form of POSIX path of theFile

set recInfo to (info for theFile as alias) as record
set DummyRec to {a:"a", b:"b"}
set testRecord to (recInfo & DummyRec)

on KeysOfRecord(rec)
	set ca to current application
	return (ca's NSDictionary's dictionaryWithDictionary:rec)'s allKeys() as list
end KeysOfRecord


set keyList to KeysOfRecord(testRecord)

keyList

Late Night Software’s Script Debugger’s variable-display lists
recInfo as a record with 20 entries
DummyRec as a record with 2 items
testRecord as a record with 22 items

If I use set keyList to KeysOfRecord(recInfo) – keyList is a list with 0 entries - I expected 20
If I use set keyList to KeysOfRecord(DummyRec) – keyList is a list with 2 entries - I expected 2 - works
If I use set keyList to KeysOfRecord(testRecord) – keyList is a list of 2 entries - I expected 22

I would appreciate any help in understanding
a) Why this script does not work as I expect
b) How do I fix it (reliably getting file record keys appears to be nearly impossible with AppleScript).

Cheers
Peter

Model: MacBook Pro Late 2011
AppleScript: 2.5
Browser: Safari 603.3.8
Operating System: Mac OS X (10.12.5)

Hi. Welcome to MacScripter.

The keys in recInfo are the reserved labels from ‘info for’, which can’t be used in NSDictionaries. The keys in DummyRec are your own user-defined labels, which can be used in NSDictionaries and are therefore returned by your script. Basically, there’s nothing wrong with the script, just the input. Or to put it another way, you can’t get reserved labels that way.

Hi Nigel,

thanks for the information. Is there a way to do what I am trying to do that you are aware of?
Ultimately I am trying to get this information in a Hazel script so that I can report on a file’s information (similar to the get info command).

I have tried several methods but each falls down at a critical point. For example I tried using (see fragment)


try
    set TextRecord to theRecord as text 
on error theError
   set text item delimiters to "{"
   set a to text item 2 of theError as string -- gets rid of the Can't make {
   set text item delimiters to "}"
   set b to text item 1 of a as string -- gets rid of trailing } into type text
   set text item delimiters to {"\", ", "\""}
   set c to text items of b as list -- creates a list of items
   set text item delimiters to tids
end try
c

which works perfectly in the AppleScript editor - but in Hazel reports the types of the keys and not the key names. Why? - I have no idea. I guessed it might be a timing issue.

Any other workable solutions would be truly appreciated. I have spent weeks on this one issue - and have learned a lot in the process - but I am getting very frustrated with this seemingly simple issue.

Cheers,
Peter

Hi all,

the answer was in another place
http://macscripter.net/viewtopic.php?id=45430
I saw this post some time ago - but did not have the knowledge to use it, until I tried to solve the problem myself. Now I understand it much better.

Thanks for checking my post.

Cheers,
Peter