Publish from Tinderbox to DEVONthink

This sounds a familiar scenario. I should note that if a template is only used to render a note content in a manner that is included in some other note (e.g. parent including only the link counts of each child note as set va the chid’s template) them make sure you’re exporting the containing note, within which use of the desired template will then show (or not).

BTW, selected note export will default to the note’s ‘normal’ location within the whole doc export but only if the doc has been fully exported once (this is how I do quick corrections for typos etc in aTbRef single pages). Otherwise you can export the file anywhere. I note this fact as if your note uses CSS, JS etc and is linked via a relative reference those links may not find their targets if not at the correct relative location.

Still, selected note export is a real boon.

Also, don’t overlook the Preview tab of the text pane.

Thanks for all your (on-target) suggestions, Mark!

I created a new note and poked around in the Attribute Inspector, finding an errant HTMLExportTemplate set to a path not beginning with my non-standard ‘/Document Management/Templates’ path. Changing that has granted me a successful HTML export. I think I’m getting there!

(oddly, I don’t have the strip above the editor with the text/preview/html toggles showing)

1 Like

See the Window menu Show/Hide Text Pane Selector to toggle the Text/Preview/HTML selector buttons on off.

The are hidden by default as if you don’t export, likely you my never need the Preview/HTML tabs.

Once set for a Doc, it remembers the toggle state and uses it for all text pane use (but not in stand-alone text windows)

Hey Adam, I’m guessing that you are using a pretty old version of this tool - one that uses $MyString to hold on to some intermediate data. The most recent version of this file no longer does that - so I think you should have no problem using them together. I will try to update the Marked exporter so it also uses custom attribute names instead of $MyString. But in the mean time, please give it a shot using the latest file, and let me know how it goes.

I just uploaded a newer version that has a “Doctor” helper to check if your document has everything it needs to run, and provides steps on how to set up the document. It should be helpful in upgrading from an older version of this tool, to the newer one. You’d need to delete the old Actions (or it might be named Stamps) container, as well as the Applescripts container. Then you can follow Doctor instructions as shown in the video below:

4 Likes

Hi Pat,

Big fan, I have been using your script since you first posted and shared it. Many, many thanks.

1 question: Is it possible to export to markdown instead of html? If so, would it be possible to explain the steps.

Thanks in advance,
Tom

Thank you for creating such easy to follow tutorial. I’m sure it will help a lot of TB and DT users. When I create the new TB document and follow these instructions, it works fine. However, when I do the same with the existing database, where the view in marked2 is implemented (Preview your Markdown notes using Marked), the links inside the notes stop working in Devonthink.

1 Like

Hi Everyone,

I’m experiencing a strange issue with Pat’s base file version 0.5.1.

I have recently purchased Tinderbox and I’m using 8.8.
I have also DevonThink Pro 3.5.2 and MacOS 10.14.6.

I followed the workflow as:

  1. Download the latest published version of the TBX file from GitHub (so by downloading the file from the tags in the GitHub page)
  2. Unzip it and open it in Tinderbox
  3. Run the stamp “Run note action” and ensure that all the steps are checked in the doctor section
  4. Create two notes at the root level of the document (Note A and Note B) and link them together using the Ziplink
  5. Run the stamp"Publish All to DevonThink"

What is strange is that while Tinderbox was in trial version, the aforementioned workflow was working as expected and I would get the notes created in DevonThink with the expected links and so on…

Now that I have activated Tinderbox, when running the stamps “Publish Note to DevonThink” or “Publish All to DevonThink”, either Tinderbox crashes instantly or nothing happen (see below for more explanation).

When I say “nothing happens”, I mean that after running the action, the icon left of “SourceURL” attribute of the selected note will blink and then nothing: no note is created in DevonThink nor no link is sent back to Tinderbox.

I tried the following with no luck:

  1. Restart the Mac
  2. Clear the caches
  3. Completely uninstall Tinderbox and re-install again fresh
  4. Un-register Tinderbox (so going back to the trial version)

I then tried to dig in what could cause the issue when “nothing happens” happens.

If I remove the “^value($DTExportSource)^” from the AppleScript “Create DEVONthink record”, then the notes get created, but obviously empty.

In the same Applescript, I replace:

  • source:"^value($DTExportSource)^"
    by
  • source:"^value($Name)^"

And it output a note with the note name as the body content.

Do you have any idea how to solve or try to debug this issue?

Thanks.

Attached my example file:
publish-tinderbox-to-devonthink.tbx (210.5 KB)

If you have a crash log, send the file and the crash log to Eastgate. The forum isn’t set up to diagnose crashes.

There is a defect in the code in the note “Update DEVONthink record”. The second line – beginning “set theRecord...” fails in Script Debugger with “expected end of line but found identifier” error. Could be the cause of the crash, or cause of the failure. I suggest starting over with the correct text for that snippet.

on run argv
  tell application id "DNtp"
    set theRecord to get record with uuid  "^value($SourceURL.replace("x-devonthink-item://", ""))^"
    set name of theRecord to "^value($Name.replace('\"', '\\~~TB_DOUBLE_QUOTE~~\"').replace('~~TB_DOUBLE_QUOTE~~', ''))^"
    set URL of theRecord to "^include(this, /Templates/TB Return URL)^"
    set tags of theRecord to "^value($Tags)^"
    set source of theRecord to "^value($DTExportSource)^"
  end tell
end run```

Thanks for your answer. I have sent an email to the support team with crash logs included.

It turns out that an error in the improved .replace operator in Tinderbox 8.8.1 can break this document if the exported note contains text links, especially if the text links are near the end of the document.

I think we have a fix, which should be backstage in an hour or so. Meanwhile, it’s really time for breakfast!

3 Likes

I too am having difficulties getting this to work even in its own document using its latest version on github 5.1.

Just curious if others are having similar issues. I agree with Paul, there appears to be a basic defect in the code as he points out.

If you’re going to work with this script, please use the b482 backstage release or later.

b482 did not work for me. Curious if anyone else has gotten it to work with their documents.
Tom

Perhaps consider using an earlier version if you don’t need the newest features? It sounds like there may have been a recent-ish update that broke some behavior that this relies on.

I am running Tinderbox Version 8.7.1 (b467) and it’s working here. I’d be curious to know from others if this is an issue of it working on my machine, or of it working on that particular version.

If you’re just copying the code from that note and pasting it into Script Editor, there’s no chance it will work. It’s not AppleScript - it’s a template that’s used to produce AppleScript that is then piped to /usr/bin/osascript.

I decided to do some tests using different version of Tinderbox (see table below) and different versions of the Publish to Devonthink file (see also table below).

For each test, I did:

  • A clean install of Tinderbox (delete cache…)
  • Download the original file from the GitHub page

Then I repeated this sequence:

  • Create a Note called “Note A” with the content “This is note A”
  • Create a Note called “Note B” with the content “This is note B”
  • Add the prototype p_DEVONITEM to both
  • Run the stamp to export the notes to DT
  • Observe the behaviour: Are the notes created in DT? Do I get back the url from DT?
  • Create a Note called “Note C” with the content “This is note C” and a zip link at the end to Note A
  • Add the prototype p_DEVONITEM
  • Run the stamp to export the notes to DT

Here is the result of those tests:

Tinderbox version Publish version Export Note A & B Export Note C TB crashes?
8.7.1 (b467) 0.4.1 Works Works No
8.7.1 (b467) 0.5.1 Works Works No
8.8.0 (b479) 0.4.1 Nothing happen Nothing happen No
8.8.0 (b479) 0.5.1 Nothing happen Nothing happen No
8.8.1 (b482) 0.4.1 Nothing happen Nothing happen No
8.8.1 (b482) 0.5.1 Nothing happen Nothing happen No

I think the issue lies in the HTML code produced.

Here is the content of the attribute DTExportSource for Note C from Tinderbox 8.7.1 (b467) and file 0.5.1:

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
	<title>Note C</title>
</head>
<body>

<h1>Note C</h1>
<p>This is note C</p>

<p><a href=\"x-devonthink-item://939D01FF-7219-4AE7-AA6C-AC459FEAE6D4\">Note A</a></p>

</body>
</html>

Here is the content of the attribute DTExportSource for Note C from Tinderbox 8.8.1 (b482) and file 0.5.1:

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv=\\\\\\"content-type\\\\\\" content=\\\\\\"text/html; charset=utf-8\\\\\\">
	<title>Note C</title>
</head>
<body>

<h1>Note C</h1>
<p>This is Note C</p>

<p><a href=\\\\\\"Note_A.html\\\\\\">Note A</a></p>

</body>
</html>

Note here all the extra backslash.

In the temple Sectional HTML page, Removing the line:

<meta http-equiv="content-type" content="text/html; charset=utf-8">

The note A and B (that contain no link) are exported to DT.
Note C not because of there are still too many backslashes in the <a> tag.

The file used being exactly the same between the version of Tinderbox, I think the issue is within Tinderbox and something has changed between 8.7.x and 8.8.x.

OK, the source tracks to this line in action in action code note “Publish single note to DEVONthink”:

$DTExportSource = $Text.replace('\"', '\\~~TB_DOUBLE_QUOTE~~\"').replace('~~TB_DOUBLE_QUOTE~~', '');

After checking a host of things it wasn’t, it looks to be a change in .replace()'s handling of it replacement string, i.e. the latter parameter.

Test (in v8.8.1) with a $Text of:

This is a " test.

The aim is to insert a literal backslash before any double quotes. If I use:

$Text("other") = $Text.replace('"','\"');

I get the $Text in note “other” to be:

This is a =" test.

But if I try to escape the backslash in the action:

$Text("other") = $Text.replace('"','\\"');

There is no output. But, using:

$Text("other") = $Text.replace('\"', '\\~~TB_DOUBLE_QUOTE~~\"').replace('~~TB_DOUBLE_QUOTE~~', ''); 

I get:

This is a \\" test.

Go figure! As @eastgate notes, there have been changes to .replace and I guess they have messed up the way backslashes are interpreted in the replacement string input to the function. In short, 1 backslash in the replace string escapes the character after it, using two 9or more consecutive backslashes in the replacement string produce no—or incorrect output.

FWIW, Tinderbox action code has always had a problem trying to escape quote characters, which presumably explains the double .replace() call in the original action. Now, where did that last hour go?

The double replace thing is a workaround for some peculiar behavior I found with replace, possibly the thing that was recently updated. I’ll see if I can accomplish the same thing without it, but am going to wait for @eastgate to weigh in first.

I’m stumped too.

The issue is still there with Tinderbox 8.9.

However I was able to solve the problem by changing in the action “Publish single note to DEVONthink”, the following code:

$DTExportSource = theExport.replace('\"', '\\~~TB_DOUBLE_QUOTE~~\"').replace('~~TB_DOUBLE_QUOTE~~', '');

by:

$DTExportSource = theExport.replace('(\w+)="([a-zA-Z0-9;\s\/\-=\._\:]+)"','$1=\\"$2\\"');

Now everything work as intended on my side, including when there is a link between notes.

Attached is the new version of Pat’s template (I named it 0.5.2 as it is built upon 0.5.1).
publish-tinderbox-to-devonthink-0.5.2.tbx (197.1 KB)

1 Like

It looks like the bottom of the heap here is finding a way for actions to escape single/double straight quotes. In noting that I’m sure that’s way less simple than my opening sentence makes it seem!