Hi,
I’ve got a (small?) problem with a script I’ve been working on. I have a data file I want to read in, and grab certain elements from; the trouble is that the file is of variable length and the item delimiters seem to change from day to day.
I’ve been able to get it running on the OSX 10.4 program, but when I try to work on it on 10.5.2, the data isn’t read in the same way, and I’m really not sure why. Finder identifies the file on both platforms as “Unix Executable” – the file itself is various values (stored in Hexadecimal) and text (stored as ASCII).
So, I read in the file, and I look at two characters within the document that provide me with the delimiters for the rest of the document:
set theContents to read (choose file with prompt “Choose the file you wish to parse”)
set Split1 to ASCII number (character 1827 of theContents)
set Split2 to ASCII number (character 1828 of theContents)
This part seems to be OK, but later on, I am trimming out things I don’t need, and at this point it seems the applescript text delimiters is truncating the data at the wrong spot – as I said, it’s running fine at the moment on OSX 10.4, but not 10.5, so I’m guessing it’s something to do with the way the file is read in.
Do I need to read the file in as “data” and then convert the hex data to a string to read it the old way?
Ugh, I’m not a real programmer and I’m just trying to get a silly script running to help us out with layouts at work.
Anyway, here’s the very rough code (please be kind – this is not polished)
– set up basic file delimiters
set originalDelimiters to AppleScript’s text item delimiters
set FirstCut to (ASCII character 12) & “Base Edition”
set SecondCut to (ASCII character 0) & “pCom”
– pick file to read
set theContents to read (choose file with prompt “Choose the ALS file you wish to parse”)
– set variable delimiters
set Split1 to ASCII number (character 1827 of theContents)
set Split2 to ASCII number (character 1828 of theContents)
set SplitText to (ASCII character (Split1)) & (ASCII character (Split2))
– parse out junk at end
set firstParse to theContents
set AppleScript’s text item delimiters to FirstCut
set trimtext to text item 2 of firstParse
set nexttext to text item 1 of firstParse
– parse out junk at beginning
set AppleScript’s text item delimiters to SecondCut
set trim2text to text item 1 of nexttext
set finaltext to text item 2 of nexttext
– split remaining good data into items
set AppleScript’s text item delimiters to SplitText
set theItems to text items 3 thru ((count of text items of nexttext) - 1) of nexttext
– figure out Y coordinates from hex numbers
set Y1A to ASCII number (character 59 of text item 1 of theItems)
set Y1B to ASCII number (character 60 of text item 1 of theItems)
set Y1C to ASCII number (character 61 of text item 1 of theItems)
set Y1D to ASCII number (character 62 of text item 1 of theItems)
set Y1Pos to ((Y1A * 256) + Y1B + (Y1C / 256) + (Y1D / 65536) - 28)
– figure out X coords etc
set X1A to ASCII number (character 63 of text item 1 of theItems)
set X1B to ASCII number (character 64 of text item 1 of theItems)
set X1C to ASCII number (character 65 of text item 1 of theItems)
set X1D to ASCII number (character 66 of text item 1 of theItems)
set X1Pos to ((X1A * 256) + X1B + (X1C / 256) + (X1D / 65536) - 916)
– eventually there will be other stuff here, etc.
So, this works fine (I have a few displays to verify the information) on the OSX 10.4 machine, but on OSX 10.5, I get “cannot get character 59 of …”
I have this sneaking suspicion I’m doing something very basic wrong here… but I can’t wrap my brain around it right now. I’ve spent too much time figuring out how the data was stored in the file and this problem is stumping me at the moment.
So, does anyone have any ideas or advice?
(and once again, I apologize for the way the code is written, this is just an experimental thing, honest!)