From database to hypertext: exporting from FileMaker Pro to Storyspace

If you’re not careful, you can waste a lot of your time just trying to move data between different platforms and apps. Although I love working in Storyspace, it is not always available, or most suitable for a given task, even if I want my data to end up as hypertext within it.

Just now I need to enter quite a lot of information about events. Although I can do some of that at my Mac, I want to be able to do so when more mobile, on my brand new iPad Pro when out enjoying the fresh air, for example. Although Tinderbox is ideally geared to exporting data in different and customisable forms, there is no (obvious) app available for both OS X and iOS which will deliver data well to Storyspace, for example.

With FileMaker Pro 15 just hitting the streets, and its wonderful free iOS partner FileMaker Go 15, this article describes the first stage of a project to create a custom database front end which will feed formatted content into Storyspace 3 and Tinderbox 6.

The idea is straightforward: in a database, content is stored in fields. Each record in the database will become a new writing space or note, and certain fields will be used to populate the attributes of each note.

The destination writing spaces or notes will contain information about events, each of which has a start and end date which I want to use for a timeline display. They also have information about the key person (‘actor’) involved in that event, its geographical location, and a free text description of the event.

FileMaker Pro

I am using FileMaker Pro Advanced version 15, which has just been released, but other recent versions should handle this fine.

I created a new database named MasaccioNotes, with just six fields:

  • Title – a text field containing the title of the event, which will become the $Title of the writing space
  • Start date – a date field to contain the starting date of the event
  • End date – a second date field
  • Actor – a text field to contain the name of the person involved in the event
  • Location – a text field giving the name of the location of the event
  • Content – the description of the event which will appear in the $Text field of the writing space when it has been processed.

sspaceb1

The only caution is that no field must contain the special characters ####, which will be the delimiter used to explode in Storyspace, or colons, as these will be used to format the text into keyword-value pairs.

sspaceb2

Having set this up, I entered a couple of example records for testing purposes. As FileMaker Pro has many different export formats, I could, for example, have opted to export the records in XML, massage them through a bit of transform wizardry, and import that. It is far simpler and more straightforward, for me at least, to write an external script which writes the records out in exactly the form that I want.

AppleScript

I use Script Debugger to develop scripts like this; although not cheap, it is far superior to Apple’s free editor, particularly when you have to wrestle bugs into submission.

sspaceb3

Currently this script iterates through every record in the database named MasaccioNotes and exports each into a single text file of your choosing, formatted ready to import into Storyspace or Tinderbox. It can readily be modified to export only those records being browsed, for example after a search, allowing you to import records incrementally as you go along.

The code is straightforward, I hope. The newline character \n is used for line endings, as that seems to work best with the Explode command in Storyspace and Tinderbox. The text generated starts with the record delimiter ####, then the title of the writing space. This is followed by a list of keyword-value pairs of the form
0: ;1:first;2:second;…

The first pair is always empty, as I found that it was not being formatted to a date reliably, perhaps because of a side-effect of Explode.

Writing the generated string to the output file is performed using a little on subroutine, because of a lexical clash over the meaning of write. Because this is within a tell window section, the meaning of write defaults to window, not a file write. Hiving the write command into a subroutine works around that issue.

I have not set file operations within the customary try command to trap errors, as I will be running this script within Script Debugger, which traps errors sufficiently for this purpose. If you want to write a standalone script or app, you should use try to trap for and handle file errors in particular.

Intermediate file

The file generated by that script is plain text all ready to be exploded by Storyspace or Tinderbox, in the form
####
Masaccio's Life
0: ;1:01/01/1401;2:01/10/1428;3:Masaccio;4:Florence;
5:Approximate life span of Masaccio.
####
Visit to Rome
0: ;1:01/03/1423;2:01/08/1423;3:Masaccio;4:Rome;
5:Visit to Rome for Papal jubilee.

Storyspace/Tinderbox

Although this is intended to be imported into my main project document, I have made a simple testbed.

sspaceb4

In a new and empty document, create a writing space and set it to be a prototype named event. Create two text user attributes, $Actor and $Location, making those key attributes of that prototype, and add $StartDate and $EndDate (from Events) as the other key attributes.

sspaceb5

To import an intermediate file, just drag it from the Finder and drop it onto the Map view. The whole of the text file will then appear in its $Text window. Then, with that writing space selected, use the Explode… command from the Note menu.

sspaceb6

Set the Explode dialog as follows:

  • Break at delimiter, with #### set as the delimiter,
  • check Delete delimiter,
  • Set the Title as the First Sentence, and check Remove title from text.

Paste in the Action
$Prototype="event"; $StartDate=$Text.at("1").substr(2); $EndDate=$Text.at("2").substr(2); $Actor=$Text.at("3").substr(2); $Location=$Text.at("4").substr(2); $Text=$Text.at("5").substr(2)
and then click on the Explode button.

This import script first sets the exploded writing space to have the event prototype. It then takes out each of the keyword-value pairs, and assigns them to their respective attributes. Finally it takes the remaining content and turns it into the new $Text for that writing space.

sspaceb7

You will then end up with the exploded writing spaces within a container, within the original writing space as its container. They will have been set to use the event prototype, with the attributes given. Occasionally this does not work the first time; if that is the case, delete the top-level container and the Prototypes container and try again.

sspaceb8

Having got this working in OS X, my next task is to make this database available to my iOS devices. I will describe that in another article.

To help you understand what I did, here is a Zip archive of my working files: fmprotosspace
Export2Text4Storyspace.scptd is the AppleScript script
FMPro2StoryspaceDemo0.tbx is the empty Storyspace document
FMPro2StoryspaceDemo1.tbx has the test file exploded into it
MasaccioNotes.fmp12 is the FileMaker Pro database
test2.txt is the intermediate text file.

Happy hypertexting.