dealing with a list of only one item!

Hi guys,
I need some help and advice. i’m going to try and keep this simple.
Whilst scripting the ‘Skim’ app I have come across a niggling issue. I use the find command to search for some text in a pdf. The errant part of the script is:


tell document 1 of application "Skim"
	set the theSel to find text "ISBN"
end tell

The script diligently fetches me a reference to that first occurrence of the text ISBN. The result is:

-->{characters 2213 thru 2216 of text of page 2 of document "An_ebook.pdf" of application "Skim"}

Now its put the resultant reference in a list, as you would expect, but only as one item. Not 4 items (one index for each character in this case). How am I, if at all possible, going to access each individual index of the characters in “characters 2213 thru 2216”.

Interestingly querying the list using:

get index for theSel 

will return → 2213.
So the list has some idea about the data within it. But then I can’t find a way to extract the other indexes. (I realise that If I could extract the first and last index so that I have some bounds to the character reference, I could then use some simple math to calculate the numbers in-between). But I’d rather have more dynamic access to the elements in my find result.
So I’m wondering if anyone else has had any experience with this kind of list problem and has any nifty workarounds. BTW the importance of the character index reference, is to find the index (position) of the last letter of ISBN, to then extract the isbn number that proceeds it.

Thanks in advance

AppleScript: 2.1.2
Browser: Safari 533.18.5
Operating System: Mac OS X (10.6)

Hi, w.harmer5476. Welcome to MacScripter.

I downloaded Skim this morning and have been fooling around with it. Its AppleScript implementation does seem a little eccentric, but I don’t know of any text application which returns a list of references to the individual characters in a section of text. You’d have to create one yourself:

tell document 1 of application "Skim"
	set the theSel to find it text "ISBN"
	
	set charRefs to {}
	if (theSel is not {}) then
		set thePage to beginning of (get pages for theSel) -- Assuming only one page is involved.
		repeat with i from (get index for theSel) to (get index for theSel with last)
			set end of charRefs to (a reference to character i of thePage)
		end repeat
	end if
	charRefs --> Individual references.
end tell

There may be better ways for those more familiar with the application.

Nigel,
Thanks for your reply. I can see now that the key bit I was getting wrong, in accessing the individual character indexes, was solved by the syntax of your line ‘get index for theSel with last. Brilliant thanks for that.

Now for my own sanity and clarification, on this data structure, would you say that in this case applescript is saving a list in an item of a list? i.e the list of individual indexes are somehow stored within the single list result ‘{characters 2213 thru 2216 of text of page 2 of document “An_ebook.pdf” of application “Skim”}’

For the sake of your sanity and clarification, it’s not AppleScript itself mucking you around, it’s a peculiarity of the AppleScript implementation in Skim. Its find command returns a range reference in a list ” why, I don’t know. The other commands don’t work with the reference by itself, but only with the reference-in-a-list. There doesn’t appear to be much you can do with the result except what’s in the script above. Either the programmer’s mad, or it’s work in progress, or it makes perfect sense when you’re more familiar with the application.

Trying to work out how application authors think is part of the fun with scriptable applications. :wink: