Wednesday, May 4, 2011

Experimental " ePubber "

In the office the other day, a lament was overheard (roughly interpreted and quoted):

"Why can't we export a Pages document on an iPad directly to iBooks on that same iPad?"

Yes, it is quite annoying that you can't do that....at least not without plugging the iPad into a computer for a sync.   The data structure of iOS is really good at producing frustration for those of us used to the wide open file structure and data model of OS X.

So, what to do.....?

How about a little bit of AppleScript?

After much playing around (I am by no means fluent in AppleScript ), much copying and pasting, and many false starts--an AppleScript was created that:

1.  Watches a Webdav folder on an OS X Server  for new files.
2.  Uses Pages on the OS X server to open Pages Mobile documents uploaded from an iPad (via Webdav).
3.  Exports the content as an ePub into a web-accessible directory.

Result:  An iPad user can create a document in Pages Mobile, upload it to a webdav directory on a server, and then (after a few seconds) download the resulting ePub to their iPad's iBooks via Safari Mobile.

Requirements for this system to work:

• The script (shown below) needs to be added to the folder of the ebdav directory as a folder action.
• The OS X server with the webdav directory needs to have Pages installed.
• You need to "prime the pump" and do an export on the server, saving that first epub to a web-accessible location on the server.  Once you do that, subsequent epubs generated by the script will get saved into that same directory.
• The server also needs to have "Enable access for assistive devices" enabled in the Universal Access pane of System Preferences.



On my server the Webdav folder is called "epub_up".  Once the script is done with it, the Pages document is automatically deleted and the epub version is placed into a folder called "epub_down" for access through Safari Mobile.

This is admittedly a fragile system that is unlikely to scale very well.  Anything that throws up an unexpected dialog box in Pages will grind everything to a halt. If care is taken, however, it can service a few people's need to create ePub documents on an iPad to get them into iBooks without syncing to a computer.

If it were possible to set up a Webdav server on a regular OS X computer (like a teacher's laptop), a teacher could have a class of students convert Pages Mobile documents to ePubs--while being able to monitor the process for problems.


Here is the script:


on adding folder items to this_folder after receiving dropped_items
delay 10
repeat with dropped_item_ref in dropped_items
tell application "System Events"
set UI_enabled to UI elements enabled
end tell
tell application "Pages"
set dropped_item_ref to dropped_item_ref as string
open file dropped_item_ref
activate
end tell
tell application "System Events"
tell process "Pages"
delay 5
click menu item "Export…" of menu 1 of menu bar item "File" of menu bar 1
set value of text field 2 of sheet 1 of window 1 to "Author: ePubber"
set value of combo box 1 of sheet 1 of window 1 to "Classics"
click button 1 of sheet 1 of window 1
end tell
                         tell process "Pages"
click button 1 of sheet 1 of window 1
click menu item "Save" of menu 1 of menu bar item "File" of menu bar 1
click menu item "Close" of menu 1 of menu bar item "File" of menu bar 1
end tell
end tell
delay 10
tell application "Finder" to delete file dropped_item_ref
end repeat
end adding folder items to