Making an index in Apple iWork Pages

9,357

I believe that this is possible, although not trivial to do with Applescript using Pages built in Applescript dictionary. It depends on exactly what sort of functionality / formatting etc. you need.

The following script might be a good starting point. In this case it searches for pages with the word "member" but you could change this to a dialogue, a list or whatever you found useful. The code is a little crude and not particularly quick but it does work.

set theSearchText to "member"
copy theSearchText to theOutputText
set theOutputText to theOutputText & "   "
set theCurrentPage to 0

tell application "Pages"
    tell document 1
        repeat with i from 1 to count of words
            set theText to text of word i
            if item 1 of theText is equal to "member" then
                set thePageNumber to the page number of the containing page of word i
                if thePageNumber is not equal to theCurrentPage then
                    copy thePageNumber to theCurrentPage
                    set theOutputText to theOutputText & ", " & thePageNumber as string
                end if
            end if
        end repeat
        return theOutputText
    end tell
end tell
Share:
9,357

Related videos on Youtube

Kurru
Author by

Kurru

You can find my blog at https://pupeno.com where I publish about coding and other stuff.

Updated on September 17, 2022

Comments

  • Kurru
    Kurru almost 2 years

    Is it possible to make an index in an IWork Pages document?

    By index I mean marking words as index worthy and at the end of the document having an alphabetical list of those words and the pages where they are mentioned. Much like any computer book out there.