Here is a quick TP3 translation of @derickfay’s Keynote script for TP2.
(Tested on Keynote 6.6.1 - Keynote’s applescript has changed, so Derick’s original script would need tweaking for TP2 too at this stage)
A few points:
- It assumes that a TP3 document, and an empty KeyNote presentation are both already open
- Copy paste the code into Script Editor (checking that it says AppleScript in the top left drop down, and click run.
- Here, I am calling the TP JS script from Applescript. It’s usually simpler really to do it from JavaScript for Applications, so that you don’t have a single page containing two languages. (Embedding JS in AS requires, for example, adding an escaping backslash before things like
\n
and\t
for newline and tab).
Essentially, TP evaluates the JS script in the context of the front document, and returns a value.
-- RUN IN SCRIPT EDITOR WITH THE LANGUAGE SET TO APPLESCRIPT
-- This part of the code is a literal JavaScript string
-- Below, in AppleScript,
-- you will see a line in which this script is evaluated
-- in the context of the front TP3 document
set strTPCode to "
function TP3Code(editor, options) {
var oOutline = editor.itemBuffer.outline,
lstProjects = oOutline.evaluateItemPath('//@type=project');
return lstProjects.map(
function (oProj) {
var lstTasks = oProj.evaluateItemPath('descendant::@type=task'),
lstNotes = oProj.evaluateItemPath('descendant::@type=note');
return {
title: oProj.body.string.split(':')[0],
tasks: lstTasks.map(
function (oTask) {
return oTask.body.string.slice(2).split('@')[0];
}
).join('\\n'),
notes: lstNotes.map(
function (oNote) {
return oNote.body.string;
}
).join('\\n')
}
}
);
}
"
tell application "TaskPaper"
tell front document
set lstProjects to evaluate script strTPCode
end tell
end tell
tell application "Keynote"
activate
tell document 1
repeat with theProject in lstProjects
tell (make new slide)
set object text of text item 1 to title of theProject
set object text of text item 2 to tasks of theProject
set strNotes to notes of theProject
if strNotes is not "" then set presenter notes to strNotes
end tell
end repeat
end tell
end tell