1

Can somebody please explain me the technical structure of an AppleScript LIST saved in a text file? There must be a length (entries counter) somewhere inside.

I had a little crash and the saved file looks like corrupt now. It always shows 1800 entries instead of 2600 before. And there are for sure more than 1800 entries. I also think it cannot be like an EOF. If I make the file shorter than 1800 I get an EOF error. If I let it longer I get just 1800 entries.

How can I fix this problem? Where can I say inside the file: hey this list has 2600 entries.

# Read List
set fileName to choose file name with prompt "Please choose log file:"
set myPeople to read fileName as list
set listCount to length of myPeople
log "Count Start: "
log listCount
...
# Save List
set f to open for access fileName with write permission
write myPeople to f
close access f

1 Answer 1

1

Technically an AppleScript list written to a disk file, in the manner you have, does not produce a text file, even though you can open it in e.g. TextEdit, or in Script Editor! It's a binary file and when opened in TextEdit, or Script Editor, you'll not see the entire contents of the file.

You need to look at it in a Hex Editor, e.g. 0xED, and the first 4 bytes are 6C697374 or list and the second 4 bytes are the number of items in the list, e.g. 00000A28 is 2600 and 00000708 is 1800.

That said, I'd restore the file from backup and not worry about how AppleScript writes a list to a disk file in the manner you have. I'd also make sure you maintain regular backups!


You can try changing the value of the second 4 bytes, but there is no guarantee it will recover the missing list items, as the file may also be corrupt in some manner or truncated. Backup the file before editing it in a Hex Editor!

Sign up to request clarification or add additional context in comments.

2 Comments

thank you so much. this was really a GREAT help but alot of work :-). Now I think i understand it. there is a number of entries at the beginning of the file and also a lenght at the beginning of each list item. there was like 20 things corrupt in my file. but now it works fine again.
@donpasquale, Appreciate the thanks, however please have a look at: What should I do when someone answers my question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.