read referenceToFile
[ from startingByte ] ¬
[ for bytesToRead | to byteToReadTo ¬
| until delimiterIncluded | before delimiterExcluded ] ¬
[ as className [ using delimiter[s] delimiters ] ]
startingByte: The offset of the byte from which to begin reading. A positive integer indicates the offset from the beginning of the file, and a negative integer indicates the offset from the end of the file.
…
I’m trying to extract ID3 1.1 tag data from an mp3, which is at the tail end of the file. So I give startingByte a negative number, but it gives me an error "Tried to position before beginning of file… "
You might want to take a look at this thread. I’m guessing that maybe you aren’t opening the file for access before attempting to read it. See ‘open for access’ and ‘close access’ in the same part of the manual. It might be helpful if you post your non-working code here for scrutiny. Sometimes it’s just a simple mistake that someone else can spot easily.
set theFile to choose file
read theFile
read theFile from -5
Apple Event Log:
tell current application
choose file
→ alias “Macintosh HD:test:numbers”
read alias “Macintosh HD:test:numbers”
→ "1234567890
"
read alias “Macintosh HD:test:numbers” from -5
→ "7890
"
end tell
As you can see, the entire file consists of the digits 1 through 0.
read returns all the data
read from -5 returns the last 5 characters (including the terminator)