Automating Bee Docs Timeline with Applescript

Using Applescript to Integrate Timelines Into Your Workflow

Applescript technologies can be used to integrate Timeline 3D with other products and data sources to automatically create timelines.

The Structure of a Timeline Document

Understanding the basic anatomy of a timeline document will help you compose your script:

  • Document: Top level object which can be opened, closed, and saved to disk. Also controls background appearance and view modes.

  • Row: Contained by a document object, and timeline can have one or more event rows. Rows can have labels and a variety of visual design settings. Please note that the Timeline user interface maintains the same visual settings for all rows in a single document, but scripting will allow you to set different values for each row individually.

  • Event: Contained by a row object. Event objects contain the data for each event as well as visual design settings such as the color.

Sample Script to Create a Timeline from Recent Mail Messages

This script shows how you can use Applescript to create timeline charts with any application that supports scripting.

tell application "Timeline 3D"
  set newDoc to make new document

  tell newDoc
    -- hide the intro panel
    set showing panel to false

    -- bulk edit view is much faster for large timelines
    set view mode to bulk edit view
    set name of first row to "MOST RECENT E-MAILS" -- set the row label

    -- create a new event for each message
    repeat with messageNumber from 1 to 20

      tell application "Mail"
        set myMessage to message messageNumber of inbox
        set mySubject to (subject of myMessage) as string
        set myDate to date received of myMessage
        set mySender to sender of myMessage
      end tell -- end tell application "Mail"

      tell first row to make new event with properties {¬
        starting date:myDate,¬
        image size:50,¬
        colorR:1.0, colorG:0, colorB:0.5, colorA:1.0}

      -- If there was a media file to associate with each event,
      -- it would be added to the properties in this format:
      -- media:"/Users/myaccount/Music/audio.mp3", 

    end repeat
    set view mode to screen view -- back to screen view after the changes
  end tell -- end tell newDoc
end tell -- end tell application "Timeline 3D"

Sample Script to Convert a Timeline to HTML

In the following script the frontmost timeline document is converted to simple HTML, one event at a time.

tell application "Timeline 3D"
  set header to "<head><style>h1, h2, p { font-family: helvetica; font-size: 9pt; margin:0} h1 { font-size: 12pt; margin-top: 25px; } h2 { font-weight: normal; font-style: italic; margin-bottom: 10px; }  p { color:#555; }</style></head>" & return & "<body style='width:400px'>" & return
  set eventContents to ""

  tell first row of front document
    repeat with myEvent in events
      set eventLabel to my encode_text(name of myEvent)
      set eventDate to my encode_text(displayed range of myEvent)
      set eventNotes to my encode_text(notes of myEvent)

      set eventContents to eventContents & tab & "<h1>" & eventLabel & "</h1><h2>" & eventDate & "</h2>" & return

      if the length of eventNotes is greater than 0 then
        set eventContents to eventContents & "<p>" & eventNotes & "</p>" & return
      end if

      set eventImage to my encode_text(image of myEvent)
      if the length of eventImage is greater than 0 then
        set eventContents to eventContents & "<img src=\"" & eventImage & "\" />" & return
      end if
    end repeat
  end tell

  set footer to "</body>"
  set output to header & eventContents & footer
end tell

on encode_text(this_text) -- required to prep text for html
  set the encoded_text to ""
  repeat with this_char in this_text
    if this_char as string is equal to "<" then
      set the encoded_text to (the encoded_text & "&lt;") as string
    else if this_char as string is equal to "&" then
      set the encoded_text to (the encoded_text & "&amp;") as string
    else if this_char as string is equal to (ASCII character 10) as string then
      set the encoded_text to (the encoded_text & "<br />") as string
      set the encoded_text to (the encoded_text & this_char) as string
    end if
  end repeat
  return the encoded_text
end encode_text