This script will export an index of annotations and source documents to an already open Numbers spreadsheet. It works best with any of the annotation templates in this thread: [url]Make an Annotation with Links, Notes, Tags v2]
The spreadsheet has 5 columns:
a) The date of the source document or annotation
b) The name of the source document or annotation
c) The page number of the source document referenced by the annotation.
d) The comments, if any to the annotation.
3) The referenced source document, if the document is an annotation.
Usage:
a) Open a numbers spreadsheet
b) Select annotations (rtf) and/or source documents (pdfs)
c) Run script
d) Choose a name for the table to be created in numbers
The script takes a set of documents like this
and turns them into a table in numbers like this
property pTitle : "Compile index to numbers"
tell application id "DNtp"
-- each headerRow column has two entries: the name of the column and its width
set headerRows to {{"Date", 71, left}, {"Description", 300}, {"Page", 71}, {"Comment", 300}, {"Source Document", 300}}
set theseRecords to the selection
set tableList to {}
set theTableName to display name editor pTitle info "Title of Index"
repeat with this_record in theseRecords
set theNote to comment of this_record
set thisUrl to URL of this_record
set theCurrentPage to ""
set theRecordname to ""
if (count of thisUrl) > 61 then
set onlypagerefs to (characters 57 through 61) of thisUrl as string
if onlypagerefs is "?page" then
set theCurrentPage to ((characters 63 through -1) of thisUrl) as string
set theCurrentPage to (theCurrentPage as integer) + 1
set theUUID to (characters 21 thru 56 of thisUrl) as string
set theRecord to (get record with uuid theUUID)
set theRecordname to (name of theRecord)
end if
end if
set record_list to {creation date of this_record as string, name of this_record as string, theCurrentPage as string, theNote as string, theRecordname as string}
set number_of_items to count tableList
set end of tableList to record_list
end repeat
-- This code is drawn from http://macosxautomation.com/applescript/iwork/numbers/examples.html
-- Build the table in an already open Numbers spreadsheet
-- theTableName must not conflict with an already existing table
tell application "Numbers"
activate
set useHeaders to true -- change to false to omit headers
if useHeaders is true then
set the rowCount to (the count of tableList) + 1
set the columnCount to (the count of item 1 of tableList)
else
set the rowCount to the count of tableList
set the columnCount to the count of item 1 of tableList
end if
-- create and populate a table reading the data as row based
tell document 1
tell active sheet
set thisTable to ¬
make new table with properties ¬
{row count:rowCount, column count:columnCount, name:theTableName, header row count:1, header column count:0}
tell thisTable
if useHeaders is true then
-- set the starting indexes for using headers
set rowIndex to 1
set columnIndex to 0
-- since headers are used, name the column & row headers
-- title and style the column header cells
set x to 1
repeat with i from 1 to the columnCount
set columnDesc to item i of headerRows
set width of column i to item 2 of columnDesc
tell cell 1 of column i
set value to item 1 of columnDesc
set alignment to center
set vertical alignment to center
end tell
set x to x + 1
end repeat
set width of column 1 to 71
set width of column 2 to 525
set width of column 3 to 71
else
-- set the starting indexes for not using headers
set rowIndex to 0
set columnIndex to 0
end if
-- populate the table with the data
set the rowCellCount to count of cells of row 2
repeat with i from 1 to count of the tableList
-- get a data set from the data set list
set thisRowData to item i of the tableList
tell row (rowIndex + i)
-- iterate the data set, populating row cells from left to right
repeat with q from 1 to the count of thisRowData
tell cell (columnIndex + q)
set value to item q of thisRowData
set alignment to center
set vertical alignment to center
end tell
end repeat
end tell
end repeat
end tell
end tell
end tell
end tell
end tell
There is an alternative version of this script which builds the table in Devonthink’s sheets. That version is more exportable to Excel or other programs:[url]Put up Example page]
Frederiko