Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1 2 
Send Topic Print
import notes from Devonthink together with tags (Read 3901 times)
Remus
Full Member
*
Offline



Posts: 3

import notes from Devonthink together with tags
Aug 01st, 2016, 7:54am
 
Hello! I know Tinderbox can export notes to Devonthink together with tags. However, I couldn't find a way to import notes from DT to TB together with their tags. I want to take notes in DT (it's much easier and faster than in TB due to a feature called sorter) and then export them in TB to explore them. For example, I want to make a concept map based on the tags I've made in DT, auto-generate links between notes, etc. As far as I've read on the forum, I think this is possible using agents.

I found that someone wrote a script for this purpose (I would have posted a link, but I can't. It is made by David Bertenshaw and can be found here: Tinderbox Users › Agent, Actions, Rules & Automation › Agent/Script for annotating by paragraph), but I don't know how to "hack the script Listing" from DT.

Can anyone help me? Is there another way to import notes from DT together with their tags? Is TB going in the future to have a drag and drop feature that also imports the tags from DT?
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: import notes from Devonthink together with tags
Reply #1 - Aug 1st, 2016, 10:26am
 
I believe Tinderbox already accepts tags in drags from DEVONthink Pro Office.
Back to top
 
 
WWW   IP Logged
Remus
Full Member
*
Offline



Posts: 3

Re: import notes from Devonthink together with tags
Reply #2 - Aug 1st, 2016, 12:53pm
 
Thank you for your response.

One can drag a tag from DT to TB, but not together with the notes that tag has. One can drag a note from DT to TB, but the tags the note from DT has are not preserved (or at least I don't know where the tags can be found; I tried adding the tag option from references to the dragged note in TB, but nothing appears).
Back to top
 
 
  IP Logged
Marc
Full Member
*
Offline



Posts: 2
Bangkok, Thailand
Re: import notes from Devonthink together with tags
Reply #3 - Aug 4th, 2016, 11:50am
 
.
I, too, am interested in linking notes between TB and DevonThink.

I am a user of DevonThink Pro Office, but I just discovered TB today and came for a look at the forum.
Some interesting topics here for DevonThink users.

On this topic, a key question is where should notes be entered first: TB or DevonThink?
As Remus states above, DevonThink's "Sorter" pop-up window is very convenient; available everywhere in OSX (DevonThink need not be running).
But, maybe TB does better when it is the first to receive notes?

As for tags, unlike Remus, I am not worried, because I never use tags.
Instead of me doing the work to assign tags, I simply enter essential key words  in text of each note; then leave it to DevonThink to work out all the cross-references.
That approach means we don't need to worry about tags at all.
Easier link to TB, yes?
Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: import notes from Devonthink together with tags
Reply #4 - Aug 4th, 2016, 4:46pm
 
My own feeling is that DEVONthink is the place for resources -- pdfs, web archives, and such -- while Tinderbox is the place for notes you write yourself.  

But much depends on your specific tasks. It's easy to move back and forth.
Back to top
 
 
WWW   IP Logged
David Bertenshaw
Full Member
*
Offline



Posts: 182

Re: import notes from Devonthink together with tags
Reply #5 - Aug 9th, 2016, 3:57am
 
I've just seen this thread and the reference to a script I wrote. I don't use that one anymore, but I do have a later attempt, which may be of use to the OP.  

From memory, it's based on work by korm, Mark Anderson and others — with slight (and clumsy) tweaks by me — in these threads: http://forum.devontechnologies.com/viewtopic.php?f=20&t=15873 and http://www.eastgate.com/Tinderbox/forum//YaBB.pl?num=1346083940/7#7.  They know what they're doing and I don't, so thanks to them, and use at your own risk!

Usage:

1. Highlight the documents in DTP, then invoke the script. This will place content on the clipboard.

1a. Open a new document in TextEdit and cmd-v paste the clipboard into it. Select the entire text (cmd-a) and copy it again (cmd-c).

2. Go to Tinderbox and click on an empty space in an outline (i.e. -- no note selected), and paste (cmd-v), to create a new note with the title "DTP Import <+ date>"

3. Explode this note, using the setting Break at Delimiter, with the delimiter "@@@" (no quotation marks, no space afterwards) and Delete Delimiter ticked.  Set Title to 'First Paragraph' and Remove Title from Text and Omit Text to unticked.

4. You should then have a new sub-document 'exploded notes' containing the new notes.  Each of these will have its $Name taken from the DTP document name. $Text will contain the body of the note, plus entries for the tags and DTP link. Tags are contained in <tg>tag1;tag1</tg> and the DTP link in <ln>x-devonthink-item:blah-blah-blah</ln> -- you then use agents (or stamps) to strip these out into the relevant attributes as before.


NB:  The step with TextEdit (1a above) is only necessary because there seems to be an issue with pasting the clipboard directly from DTP into TBX — when you explode the note, it puts the entire text into $Name, rather than just the title. I think this is new behaviour and I've no idea why it's happening, or whether it's something to do with TBX or DTP causing the problem. I'll investigate, but in the meantime, step 1a (doing an interim copy and paste and copy in TextEdit) seems to cure the problem.

The script:

Code:
-- exports selected DEVONthink records to clipboard for pasting into Tinderbox
-- http://www.eastgate.com/Tinderbox/forum//YaBB.pl?num=1346083940/7#7
-- http://forum.devontechnologies.com/viewtopic.php?f=20&t=15873
-- expanded to include "quotified" multi-paragraph text

-- Modified by me (DB) 14/8/2014
-- Add tags

set pTab to tab -- "tab" has a specific meaning to DEVONthink so use "pTab" in tell block
set theDate to current date

--Set up tab-separated-values table "header" with Tinderbox attribute names:
-- set dataString to "Name" & pTab & "URL" & pTab & "Tags" & "Text" & return
set dataString to "DTP Import " & theDate & return

tell application id "com.devon-technologies.thinkpro2"
	set itemList to selection
	if itemList is {} then
		tell application "System Events" to display dialog "Oops! ... First select some DEVONthink records and try again." buttons "OK" default button "OK"
	else
		repeat with anItem in itemList

			set old_delim to AppleScript's text item delimiters
			set AppleScript's text item delimiters to ";"
			set theTags to the tags of anItem as text
			set AppleScript's text item delimiters to old_delim

			set aText to rich text of anItem

			--replace any straight quote with curly/smart, and surround with straight double quotes:
			set quotifiedText to quote & my quotify(aText) & quote

			--add a tab-separated-values "data row" to the pile:
			set dataString to dataString & "@@@" & (name of anItem) & return & return & quotifiedText & return & return & "<ln>" & (reference URL of anItem) & "</ln>" & return & "<tg>" & (theTags) & "</tg>" & return

			-- set dataString to dataString & "@@@" & (name of anItem) & pTab & "<ln>" & (reference URL of anItem) & "</ln>" & pTab & "<tg>" & (theTags) & "</tg>" & pTab & quotifiedText & return

		end repeat

		set the clipboard to dataString as Unicode text

		tell application "System Events" to display dialog "DEVONthink data placed successfully on clipboard! … Now click Tinderbox outline view (not an open note) and hit <command-v> to paste." buttons "OK" default button "OK"
	end if
end tell

on quotify(txt)
	-- replace straight quotes with curly/smart versions
	--"quoted form" of mwra quotify() <http://www.eastgate.com/Tinderbox/forum//YaBB.pl?num=1265006946/0#4>
	set scrptCom to "sed 's:\"\\([^\"]*\\)\":“\\1”:g' | sed \"s:'\\([d|ll|re|s|t|ve]\\):’\\1:g\" | sed \"s:'\\([^']*\\)':‘\\1’:g\""
	return do shell script ("echo " & quoted form of txt & " | " & scrptCom)
end quotify



return dataString -- (optional) display in AppleScript Editor Result pane 




Hope this helps -- good luck.
Back to top
 
« Last Edit: Aug 9th, 2016, 3:59am by David Bertenshaw »  
  IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: import notes from Devonthink together with tags
Reply #6 - Aug 9th, 2016, 3:27pm
 
Thanks for posting this. The picket fence that resulted from "escaping" Mark A's quotify sed (so AppleScript would accept it) is a trip down memory lane.

Here, using 6.6.2, I can follow your steps without going through TextEdit.

Here's a simplified script that places selected DT items on the clipboard while preserving tags.

Usage: 1) select the items in DT, 2) run the script, 3) click a Tinderbox view (not in an open note) and command-v to paste.

Tinderbox "spreadsheet import" cleverly places the values in their proper places (assuming the "header" row in the data is set up properly, as in this example) with no need to explode a note.

Code:
-- Exports selected DEVONthink records to clipboard for pasting into Tinderbox
-- Tinderbox treats as "spreadsheet import" -- automatically maps values to attributes named in "header"

set pTab to tab -- use pTab since tab has special meaning in DEVONthink tell blocks

-- Tab-separated-values "header" with Tinderbox attribute names
set pasteStr to "Name" & pTab & "URL" & pTab & "Tags" & pTab & "Text" & return
set text item delimiters to ";" -- to separate tags in Tinderbox attribute
tell application id "com.devon-technologies.thinkpro2"
	set selectedItems to selection
	try
		repeat with anItem in selectedItems
			tell anItem to set pasteStr to pasteStr ¬
				& name & pTab & reference URL & pTab & tags & pTab & my quotify(rich text) & return
		end repeat
		set the clipboard to pasteStr
		display notification "DT data placed on clipboard… Click a Tinderbox view (not in an open note) and hit <command-v> to paste."
	on error
		display dialog "Oops! Select some DT items and try again." buttons "Cancel"
	end try
end tell
set text item delimiters to ""

on quotify(txt) -- mwra quotify() <http://www.eastgate.com/Tinderbox/forum//YaBB.pl?num=1265006946/0#4>
	set scrptComm to "sed 's:\"\\([^\"]*\\)\":“\\1”:g' | sed \"s:'\\([d|ll|re|s|t|ve]\\):’\\1:g\" | sed \"s:'\\([^']*\\)':‘\\1’:g\""
	do shell script ("echo " & txt's quoted form & " | " & scrptComm)
end quotify

return pasteStr -- (optional) display in AppleScript Editor Result pane  

Back to top
 
« Last Edit: Aug 9th, 2016, 3:30pm by Sumner Gerard »  
  IP Logged
WAKAMATSU
Full Member
*
Offline



Posts: 18
Japan
Re: import notes from Devonthink together with tags
Reply #7 - Aug 10th, 2016, 2:07am
 
Dear Sumner Gerard and David Bertenshaw,

Thanks a lot for posting about DEVONthink.

Quite interesting !!

I may ask for the participation of some of you, and please say yes to a request, attempting a translation from this CODE to Keyboard Maestro Macro ?

Yours, WAKAMATSU Smiley
Back to top
 
 
  IP Logged
Remus
Full Member
*
Offline



Posts: 3

Re: import notes from Devonthink together with tags
Reply #8 - Aug 10th, 2016, 5:34am
 
Wow, that's great! Thanks a lot guys!
I have tested both scripts with various notes. Although coming with a better workflow, the second script has some limitations: if the note has two or more paragraphs, the script will split them in multiple notes. One should write a note continuously.
Both scripts cannot preserve the formats in the notes (italics, etc.).

Once again, thank you very much for your efforts. It will help me a lot.
Back to top
 
 
  IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: import notes from Devonthink together with tags
Reply #9 - Aug 10th, 2016, 1:48pm
 
Quote:
if the note has two or more paragraphs, the script will split them in multiple notes.


If you typically have multi-paragraph notes in DEVONthink, you can do this:

Change the line containing Mark A's magnificent 'quotify' from:

Code:
set scrptComm to "sed 's:\"\\([^\"]*\\)\":“\\1”:g' | sed \"s:'\\([d|ll|re|s|t|ve]\\):’\\1:g\" | sed \"s:'\\([^']*\\)':‘\\1’:g\"" 



to:

Code:
set scrptComm to "sed 's:\"\\([^\"]*\\)\":“\\1”:g' | sed \"s:'\\([d|ll|re|s|t|ve]\\):’\\1:g\" | sed \"s:'\\([^']*\\)':‘\\1’:g\" | tr '\\n' '|'" 



I tacked an extra bit of code on the end that transforms any newline to a pipe character (|).  That way the data string can be pasted into Tinderbox without creating a new note.

Then on the Tinderbox side select the pasted notes and apply a stamp like this:

Code:
$Text=$Text.replace("\|","\n") 



If you have pipe characters in your original notes that you need to preserve you could use ` instead of | in both the script and the stamp. In the script it's the last | in the line with sed and tr.

Quote:
Both scripts cannot preserve the formats in the notes (italics, etc.).


Alas, I don't know a workaround for that. Perhaps Mark B or Mark A could comment whether spreadsheet import can preserve original text formatting if the user includes an indicator of some kind to the tab-delimited data (in which case the script could be changed to incorporate that).  I see that dragging a note from DT does preserve the formatting, so perhaps there is a way.

And a question on tags:  When Tags is used in the header line for spreadsheet format a $Tags attribute is populated.  But it doesn't seem to be a User Attribute and so far I haven't been able to find it elsewhere.  Where does it live?  (If I use MyTags in the header a user attribute named $MyTags is automatically created if it doesn't already exist.)



Back to top
 
« Last Edit: Aug 10th, 2016, 1:59pm by Sumner Gerard »  
  IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: import notes from Devonthink together with tags
Reply #10 - Aug 11th, 2016, 11:33am
 
I finally found where the $Tags attribute is. It's under References.

My question is still unanswered re preserving text formatting with spreadsheet import. Is there a way?  

(I *think* the answer is that a direct drag from DT can bring in text formatting but not DT tags, whereas spreadsheet import can bring in tags but cannot preserve formatting.)
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: import notes from Devonthink together with tags
Reply #11 - Aug 11th, 2016, 12:34pm
 
I believe that summary is true. My understanding is 'Spreadsheet' import was originally for importing tab-delimited text, ergo un-styled text. Tag data would be a column in the imported data table.

As regards copy/paste and drag/drop, this regards both apps engineers to use a common process. Dragging a note - with all it's info - is more complex than dragging some (styled) text as both ends need to know how to pack/un-pack the extra metadata like tags. It's the sort of thing I've learned to to assume won't 'just' work unless I know otherwise.  I guess this is a feature request - for those interested to make - to both apps.
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
David Bertenshaw
Full Member
*
Offline



Posts: 182

Re: import notes from Devonthink together with tags
Reply #12 - Aug 12th, 2016, 9:46am
 
Sumner,

"Here, using 6.6.2, I can follow your steps without going through TextEdit."

Yes, I used to be able to as well. No idea what the glitch is, so I included the TextEdit workaround as a temporary measure while I work out what's going on. Annoying.
Back to top
 
 
  IP Logged
Sumner Gerard
Full Member
*
Offline



Posts: 359

Re: import notes from Devonthink together with tags
Reply #13 - Aug 12th, 2016, 6:36pm
 
Hi David,

Quote:
I used to be able to as well. No idea what the glitch is, so I included the TextEdit workaround as a temporary measure


I can reproduce your problem here. The string generated by AppleScript just doesn't explode as expected after pasting into Tinderbox (everything ends up in $Name).  But Tinderbox will explode text that is first copied into TextEdit then selected and pasted into Tinderbox, as long as Format is set to 'Rich text' in TextEdit Preferences. If set to 'Plain text', then going through TextEdit doesn't seem to help.  (But, pasting as plain text into another app such as nvALT then selecting, copying and pasting to Tinderbox does work here!)

Anyway, the 'Rich Text' setting in TextEdit got me to thinking Tinderbox might be able to handle rich text better if the AppleScript could generate that. That's not so easy. But I ended up with the workaround below, which may do the trick for you if the "Spreadsheet import' doesn't suit.  Would be interested to know if it works on your end. After running, you should be able to paste straight into Tinderbox.

In due course this apparent oddity with Explode will perhaps be addressed.

Code:
-- exports selected DEVONthink records to clipboard for pasting into Tinderbox to explode
set explodeDelim to "@@@" -- in Tinderbox use this delimiter to explode
set dataString to "DTP Import " & (current date) & return
set text item delimiters to ";"
tell application id "DNtp"
	repeat with anItem in (get selection)
		tell anItem to set dataString to dataString ¬
			& explodeDelim ¬
			& name & return ¬
			& plain text & return ¬
			& "<ln>" & reference URL & "</ln>" & return ¬
			& "<tg>" & tags & "</tg>" & return
	end repeat
end tell
set text item delimiters to ""

-- workaround to convert to rtf and place on clipboard
do shell script "echo " & dataString's quoted form & ¬
	" | textutil -stdin -convert rtf -font 'Hoefler Text' -fontsize 16 -stdout | pbcopy"

return dataString -- (optional) display in Script Editor Result pane  




Back to top
 
« Last Edit: Aug 12th, 2016, 8:54pm by Sumner Gerard »  
  IP Logged
David Bertenshaw
Full Member
*
Offline



Posts: 182

Re: import notes from Devonthink together with tags
Reply #14 - Aug 15th, 2016, 8:22am
 
Hi Sumner -- thanks very much!

I'm not in a position to test it out for a couple of days, but I'll try it and report back. Thanks!
Back to top
 
 
  IP Logged
Pages: 1 2 
Send Topic Print