Reading a file offset from EOF not working?

Based on the basic scripting additions manual:

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… "

So is this not working right on OS X or what?

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.

Actually i am using open for access/close access just fine.

I’m just wondering if this is an OS X scripting issue.

In the meantime I’ve made a workaround-- Getting the length of the file:

set filelength to (size of file filepath of app “Finder”) as integer

and calculating it from there so I could use a positive seek value.

It’s just a lot more elegant if Apple could keep AppleScript as close to its own published spec as much as possible.

I can’t see a problem here. Tested on 10.2.3:

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)