AppleScript to Export Notes in OPML

Users asking other users for AppleScripts that work with Bookends.
dave83
Posts: 38
Joined: Fri Oct 02, 2015 8:55 am

Re: AppleScript to Export Notes in OPML

Post by dave83 »

Jon,

Thanks.

Aside from that digital ball and chain called e-mail, my main tools are Bookends, Scrivener and a genealogy program called Evidentia. All are written by individual entrepreneurs with constant connections with their users. A strong powerful testament to the value of listening to customers, engaging and helping solve issues, and commitment to their product. Again, thank you!
Cheers,
Dave
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: AppleScript to Export Notes in OPML

Post by iandol »

dave83 wrote:No, I use the Bookends keywords. They are embedded in within the notes and preceded with the percent sign (%).


Hm, my BE keywords are not included in the OPML output, and I can't see how they are processed? Do you manually add them to your notes or how does the OPML script do this?
dave83 wrote:Thanks for the improvements. When you added the URI, does Scrivener recognize it; thus allowing you to link to the reference?
No, the URL is not linked. I also tried using html <a/> just on the off-chance but no luck either, and using CDATA to encode the html links, also no luck. We will need Keith to modify the OPML import.

Anyway, you can easily convert them to hyperlinks in Scrivener, just type a space after the URL. Here are my changes to your code:

https://gist.github.com/iandol/4266b62e ... ed4cbd7211

See line 214+. I've added DOI, PMID, URL and BibTeX key, and do add the bookends:// link too.
AsafKeller
Posts: 64
Joined: Thu Jul 05, 2007 1:07 pm

Re: AppleScript to Export Notes in OPML

Post by AsafKeller »

I prefer to use PMID for citations to allow for collaboration with colleagues that use other Bookends libraries.
I can't figure out where, in the script, to replace BE's unique ID with user18; would appreciate guidance. Thanks!
AsafKeller
Posts: 64
Joined: Thu Jul 05, 2007 1:07 pm

Re: AppleScript to Export Notes in OPML

Post by AsafKeller »

iandol: Thanks for posting this. The OPML file I generate with your code cannot be read by Scrivener, Tinderbox, or OmniOutliner. I tried debugging but failed. Thanks.
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: AppleScript to Export Notes in OPML

Post by iandol »

Dear Asaf,

Yes, it is possible that the DOI or URL contains unescaped characters that are invalid for OPML files. I've not had any problems so far. In other languages it is easy to fix, but applescript is generally terrible and has few native functions to help in these sorts of tasks. I tried using CDATA (which should stop any XML parsing) but Scrivener's parser can't handle it.

Can you please send me an example OPML file that fails? I can work out if the problem really is the unescaped characters.

Where exactly do you want the PMID? We can add it to the title or within the main text, or only in the note like the temporary citation? I've put the BibTeX user key in the main text as that is most useful to my workflow.
AsafKeller
Posts: 64
Joined: Thu Jul 05, 2007 1:07 pm

Re: AppleScript to Export Notes in OPML

Post by AsafKeller »

Thanks for helping with this. I'm attaching a sample output file.
I would like the PMID to appear in the citation key (instead of the unique id), if possible.
Thanks again!
Attachments
BE-to-OPML.opml.zip
(1.8 KiB) Downloaded 1355 times
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: AppleScript to Export Notes in OPML

Post by iandol »

Yes, as I suspected it was the URLs (although it does load in my Scrivener). Anyway I've added proper URL encoding and I've used xmllint tool to verify the XML is now compliant.

I've also added some user options at the top:

Code: Select all

--User Options---------------------------------------------------------------------
set showCitation to true -- show temp citation in main text (it will always be shown in the child notes)?
set citationPMID to true -- replace the uniqueID with PMID in the temp citation if present
set useBibTeXKey to false -- use BiBteX formatting for temp citation
This will show temporary citations in the main text, and use the PMID instead of uniqueID. Set to false,false,false should be Dave's preference, true,true,false to yours, and true,false,true is my preference 8)

See the Code / Download

I've also put the "metadata" below the abstract:
Screen Shot 2017-08-05 at 15.59.12_SMALL.png
Screen Shot 2017-08-05 at 15.59.12_SMALL.png (60.72 KiB) Viewed 72082 times
AsafKeller
Posts: 64
Joined: Thu Jul 05, 2007 1:07 pm

Re: AppleScript to Export Notes in OPML

Post by AsafKeller »

This is incredibly useful; thank you so much!
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: AppleScript to Export Notes in OPML

Post by iandol »

Agreed, many thanks to Dave who took the bull by the horns to tackle this. Trying to build scripts with Applescript always gives me headaches, so I can't imagine how much effort Dave put into this!!!

There is a thread on the forums showing how to use Javascript instead of Applescript, but I haven't tried it yet: viewtopic.php?f=2&t=4017&p=18356 — seems like this would make these kinds of scripts much easier — most importantly that you can DEBUG using Safari's tool!
dave83
Posts: 38
Joined: Fri Oct 02, 2015 8:55 am

Re: AppleScript to Export Notes in OPML

Post by dave83 »

Thanks for the updates. This is finally a great tool. I appreciate the comments, but more imporatantly the open collaboration.
Cheers,
Dave
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: AppleScript to Export Notes in OPML

Post by iandol »

One thing I didn't understand but left as is, is <iimg> a typo or deliberate:

Code: Select all

--set image content tags
set open_image_tag to "<iimg>"
set end_image_tag to "</iimg>"
I don't have any images in my notes so don't know what it is supposed to be...

EDIT, I also updated script to V1.14 to fix some formatting errors for the note stream contents (page numbers cannot use @ in BibTeX citations etc., if you click on revisions on the gist page you can see the differences), and not escape all the forward slashes in URLs, looks a bit nicer in Scrivener...
dave83
Posts: 38
Joined: Fri Oct 02, 2015 8:55 am

Re: AppleScript to Export Notes in OPML

Post by dave83 »

I'll get on gisthub tomorrow to get the revised code. I can't thank you enough for making this a better tool.

As for the images, the tags <iimg> and </iimg> encapsulate the image. I discovered this using the iHex application on the resulting .opml file after I tested the script with an image I captured using Bookends. The OPML structure does not resolve images, so I just strip them out and insert a note that the image was stripped. It's a trade-off to use OPML, so I just know that if I really need the image, then I will have to manually cut/paste it over to Scrivener.
Cheers,
Dave
iandol
Posts: 465
Joined: Fri Jan 25, 2008 2:31 pm

Re: AppleScript to Export Notes in OPML

Post by iandol »

I can't get images in the note stream at all, and I thought the note stream was text only? Also, HTML markup should be <img>, not <iimg> which was why I am a bit confused about this.
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: AppleScript to Export Notes in OPML

Post by Jon »

Right, no images in Notes. Is suspect this is a leftover from the corresponding script that was used with Sente, which can contain images in Notes.

Jon
Sonny Software
dave83
Posts: 38
Joined: Fri Oct 02, 2015 8:55 am

Re: AppleScript to Export Notes in OPML

Post by dave83 »

I had images from when I imported from Sente. I added this feature to account for others who might also transition from Sente.
Cheers,
Dave
Post Reply