Linking and Tagging questions

I have a particular scenario and I am wondering about the most effective method of achieving it, which I presume would be through scripting.

I have Document A contained in Group A. I want to select some text in Document A and drag it to a tag in my Tags group. This creates a new record in the Tag/Group that I drag to containing the text dragged.

I would like this new record to have a link back to Document A included after the text (ideally the link would take you to the location of this text in Document A), and for the record to be moved to Group A, meaning that it would pick up the tag for Group A.

I am wondering what the best way of automating this would be. If I was to go down the scripting route then presumably there would be no way of choosing which tag to add the text to other than entering the text for the tag in a dialogue box, which would mean having to type the tag each time, rather than just dragging to a tag.

Ideally there would be a way of moving the new record to Group A and adding the link to Document A on dragging to the tag, but this may be stretching possibilities.

I would be interested to hear what others think about this scenario.

Thanks

Nick

Drag & drop isn’t scriptable and therefore the only solution is probably to use a dialog to enter the tag.

Thanks, as I suspected.

So the sequence for the script would be something like:

  1. Create new record in Group A from text in Document A
  2. Add link to Document A underneath text in new record. Can this link specify location of the text in Document A?
  3. Add tag to new record through Dialog Box

I am able to script Part 1, and can have a go at Part 3, but adding the link eludes me. I have looked in the Applescript dictionary for DT and can’t find an entry for link.

Could someone help with this?

Thanks

Nick

I have sorted Parts 1 and 3 like this:

tell application id "com.devon-technologies.thinkpro2"
	
	set selText to selected text of window 1
	display dialog "Enter tags to add:" default answer "" buttons {"Cancel", "OK"} default button 2
	set newTag to the text returned of the result
	create record with {name:selText, type:rtf, plain text:selText, tags:newTag} in current group
	
end tell

This allows for multiple comma delimited tags to be added to the new record.

With regards to part 2 it would seem like I need to define the URL for Document A (i.e. set thisURL to URL of…) and then add it to the text (i.e. plain text:selText & thisURL).

I am not sure what to add to “set thisURL to URL of…” to make thisURL the URL of Document A, and whether the URL can include the location of the text in Document A (like a bookmark in a PDF).

Finally, I would also like to do the following:

  1. highlight the original selected text in yellow after it has been copied into the new record. From a bit of searching round it would seem that I need to use set background, but I am not sure how to script this.
  2. add the newly created records to a group under the current group called “snippets”
  3. name the new records by the same name as Document A

Sounds like you haven’t cosy’ed up to attribute runs as I had suggested.

C.

well, I ran your ‘attribute run’ script and it came up with all sorts of content that I couldn’t really make sense of. then I looked at attribute run in the applescript dictionary for DT and can understand what it is, but can’t work out how I would use this to build a URL to the selected text in Document A.

An alternative to attribute runs is always to use the clipboard, and (if you find HTML more intelligible than RTF) conversion between the two formats.

You may find some re-usable idioms in this fragment, which fills the clipboard with an RTF link to a url:

set {strURL, strTitle} to {"", ""}

set strURL to text returned of (display dialog "Enter a URL:" default answer "http://" with title "Make Link")
set strTitle to text returned of (display dialog "Enter a title for the link:" default answer strURL with title "Make Link")

if (strURL is not "") and (strTitle is not "") then
	set strHTML to quoted form of ("<font face=\"helvetica\"><a href=\"" & strURL & "\">" & strTitle & "</a></font>")
	do shell script "echo " & strHTML & "  | textutil -format html -convert rtf -stdin -stdout | pbcopy -Prefer rtf"
end if

Thanks, but I am still struggling to get my head round the URL creation.

I am hoping there is a way of using a statement like:

“set thisURL to URL of Document A”.

Even better would be:

“set thisURL to URL of position of selected text in Document A”

where the URL when clicked would take you to the position in Document A where the text in the Snippet came from.

But maybe I’m barking up a wrong tree… :confused: