Convert all pages in document

Erik Ackerman's Avatar

Erik Ackerman

02 Jan, 2020 01:26 PM

I have a document that's evolved over the years and now has pages of all different formats (plain text, rich text, markdown). I'd like to make all the pages consistent, but don't want to go page by page selecting Format > Convert Page To…> Rich Text. Enter the wonderful world of scripting and VoodooPad's awesome plugin support. I can write a script to walk through every page of the document, but I can't figure out what method and argument I need on each page to covert the page type. I'm quite willing to believe that I'm overlooking the documentation on this, and I've tried poking around some. I thought I had it when I found setType_ on the page object, but type() just returns "page", so that doesn't seem to be it.

  1. Support Staff 1 Posted by John on 03 Jan, 2020 03:37 AM

    John's Avatar

    The item conversion code is gnarly and isn't exposed through the scripting interface, so there's currently no way to convert items from one format to another via a script.

  2. 2 Posted by Erik Ackerman on 03 Jan, 2020 02:02 PM

    Erik Ackerman's Avatar

    That would certainly explain why I had trouble figuring it out. Thanks! How about being able to tell from a script which format a page is in, so I don’t have to manually walk through every page to check?

  3. Support Staff 3 Posted by John on 13 Jan, 2020 06:02 AM

    John's Avatar

    You can call uti() on an item to determine its type:

    var item = document.pageForKey(itemName);
    print(item.uti());
    

    You'll get a UTI back (e.g., public.utf8-plain-text) rather than a straightforward type name, but text pages generally only have a handful of types:

    • com.apple.rtfd
    • net.daringfireball.markdown
    • public.utf8-plain-text
  4. 4 Posted by Erik Ackerman on 13 Jan, 2020 11:43 AM

    Erik Ackerman's Avatar

    Perfect! Thank you.

    Erik

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac