Skip to content

Instantly share code, notes, and snippets.

@wastemobile
Created June 21, 2014 01:37
Show Gist options
  • Save wastemobile/cfd10d0a943f1900ca7d to your computer and use it in GitHub Desktop.
Save wastemobile/cfd10d0a943f1900ca7d to your computer and use it in GitHub Desktop.
Generate FoldingText TOC with Applescript
tell application "FoldingText"
tell front document
evaluate script "function(editor, options) {
var tree = editor.tree(),
headings = tree.evaluateNodePath('//heading'),
toc = [];
headings.forEach(function(each) {
var level = each.typeIndentLevel(),
text = '- ' + each.text();
while (level > 1) {
text = ' ' + text;
level--;
}
toc.push(text);
});
toc = toc.join('\\n');
require('ft/system/pasteboard').Pasteboard.writeString(toc);
return toc;
}" with options {}
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment