Quote from clipboard (through script)

Hi
I use DT in conjunction with skim and trying to find a way to copy highlight notes from skim in DT. I was able to make skim create a highlight note and copy the text to clipboard. What I’d like to do now is to simulate automatically what does the “Quote from clipboard” template, is it possible through script (without GUI scripting)?
In this way I could just select some text, run the script and have the highlight note created in skim and the content in a quote in DT
Thanx
Nestor

This script is based on an example script “New Notes for Selection” found in the Skim project wiki page on the topic “Applescript”. I merely added a call to a function to create a record in DTPO.

Make a selection in Skim, run the script (inside Skim, not in DTPO). The script prompts for the type of Skim note you want (highlight, underline, strike out, circle box), makes the note in Skim, activates DTPO and prompts for a name for the record, adds the record to the destination set in Preferences > Import, returns to Skim.

The note in DTPO is not linked to the Skim document and could be made more intelligent in this respect.

Use at your own risk.

-- Make a note in Skim; make a record in DTPO using the selection from Skim
-- See DT forum thread found at: http://www.devon-technologies.com/scripts/userforum/viewtopic.php?f=20&t=10929
-- Based on Skim wiki example script found at http://skim-app.sourceforge.net/scripts/New%20Notes%20for%20Selection.scpt
-- The bits added for the DTPO portion are found between brackets thus: -- > Start DTPO / -- < End DTPO
-- use at your own risk
-- made May 21, 2010 by korm

tell application "Skim"
	activate
	
	if (count of documents) is 0 then
		beep
		display dialog "No documents found." buttons {"•"} default button 1 giving up after 3
		return
	end if
	
	if (length of (get selection of document 1)) is 0 then
		beep
		display dialog "No selection found." buttons {"•"} default button 1 giving up after 3
		return
	end if
	
	set noteType to my chooseNoteType({"Highlight", "Underline", "Strike Out", "Circle", "Box"})
	if noteType is 0 then return
	
	set numberOfNotes to 0
	
	tell document 1
		set thePages to (get pages for (get selection))
		repeat with aPage in thePages
			set aPage to contents of aPage
			set theSel to my subSelectionOnPage(selection, aPage)
			if length of theSel > 0 then
				set numberOfNotes to numberOfNotes + 1
				tell aPage
					if noteType is highlight note or noteType is underline note or noteType is strike out note then
						set theNote to make note with properties {type:noteType, selection:theSel}
					else
						set theBounds to get bounds for theSel
						set theNote to make note with properties {type:noteType, bounds:theBounds}
					end if
				end tell
				set text of theNote to (get text for theSel)
				-- > Start DTPO begin add note to DTPO
				set myRecordText to (get text for theSel) as string
				set myDTPONote to my makeDTPONote(myRecordText)
				-- < End DTPO end add note to DTPO
			end if
		end repeat
	end tell
	
	beep
	-- > Start DTPO : there was a bug in the Skim example script in the following line; fixed
	display dialog "Done adding " & numberOfNotes & " notes." buttons {"OK", "Cancel"} default button 1 giving up after 5
	-- < End DTPO : end bug fix
	
end tell


on subSelectionOnPage(theSelection, thePage)
	tell application "Skim"
		-- normalize the selection
		join theSelection
		set theSubSelection to {}
		repeat with aSelectionRange in theSelection
			set aSelectionRange to {contents of aSelectionRange}
			if thePage = first item of (get pages for aSelectionRange) then
				set end of theSubSelection to aSelectionRange
			end if
		end repeat
		return theSubSelection
	end tell
end subSelectionOnPage


on chooseNoteType(typeList)
	tell application "Skim"
		set theResult to choose from list typeList with prompt "Note type:"
		if theResult is false then return 0
		set noteTypeString to theResult as string
		if noteTypeString is "Text Note" then
			return text note
		else if noteTypeString is "Anchored Note" then
			return anchored note
		else if noteTypeString is "Circle" then
			return circle note
		else if noteTypeString is "Box" then
			return box note
		else if noteTypeString is "Highlight" then
			return highlight note
		else if noteTypeString is "Highlight" then
			return highlight note
		else if noteTypeString is "Underline" then
			return underline note
		else if noteTypeString is "Strike Out" then
			return strike out note
		else if noteTypeString is "Line" then
			return line note
		else if noteTypeString is "Freehand" then
			set end of noteTypes to freehand note
		end if
	end tell
	return noteType
end chooseNoteType

-- > Start DTPO
on makeDTPONote(theSelection)
	set DTPOflag to "Fail"
	tell application id "com.devon-technologies.thinkpro2"
		activate
		display name editor "Enter document name" default answer "Copy of Skim Note"
		set theName to the result
		create record with {name:theName, rich text:theSelection, type:rtf}
		set DTPOflag to "OK"
	end tell
	tell application "Skim"
		activate
	end tell
	return DTPOflag
end makeDTPONote
-- < End DTPO

Thanks Korm
I had used the same skim script. Actually what I intended was to have the text in the clipboard directly pasted in the DTO template “Quote from clipboard” and (possibly) being asked if I want to edit it (to immediatly write a comment) or just come back to skim
any help appreciated
:wink:
Nestor

…or in a template like this:

%styledClipboard%%clipboardLink%

(p.?)

Comments:
HERE

Keywords:
HERE

Hi,

I created a script for a similar purpose before finding your post here (did not see that there is a special Scripting forum :frowning:).

I did not yet try your, but if I correctly understood, your devon think note will not be related to the original pdf.

I used the create rtf note service by hitting Cmd-Shift-")" and then the note automatically contains the URL pointing to the original PDF file which is very handy.
The script takes the selected text, highlights it in green and then open the window for renaming and tagging he RTF note.

[b]The problem is (I’m not entirely happy with it), that I’d like to modify the title of the note and already jump to the tags field to enter some keywords here (would save me hit “tab” 2 times, but I could not solve that).

Can someone help?
[/b]

(remark: There are a lot of unnecessary lines commented out in the script.)


--modifiziert MB 2011-03-04

tell application "Skim"
	activate
	
	if (count of documents) is 0 then
		beep
		display dialog "No documents found." buttons {"•"} default button 1 giving up after 3
		return
	end if
	
	if (length of (get selection of document 1)) is 0 then
		beep
		display dialog "No selection found." buttons {"•"} default button 1 giving up after 3
		return
	end if
	
	--set noteType to my chooseNoteType({"Highlight", "Underline", "Strike Out", "Circle", "Box"})
	--if noteType is 0 then return
	set noteType to ""
	
	set numberOfNotes to 0
	
	tell document 1
		set thePages to (get pages for (get selection))
		repeat with aPage in thePages
			set aPage to contents of aPage
			set theSel to my subSelectionOnPage(selection, aPage)
			if length of theSel > 0 then
				set numberOfNotes to numberOfNotes + 1
				tell aPage
					--if noteType is highlight note or noteType is underline note or noteType is strike out note --then
					set theNote to make note with properties {type:highlight note, selection:theSel, color:green}
					--set theNote to make note with properties {type:noteType, selection:theSel}
					--else
					--set theBounds to get bounds for theSel
					--set theNote to make note with properties {type:noteType, bounds:theBounds}
					--end if
				end tell
				set text of theNote to (get text for theSel) & " #DTPro"
			end if
			
			tell application "System Events"
				keystroke ")" using {command down, shift down}
				--	set frontApp to a reference to item 1 of (every process whose frontmost is true)
				--	tell frontApp
				--		keystroke tab --using command down
				--		keystroke tab
				--		keystroke tab
				--	end tell
			end tell
			--	tell application "System Events" to keystroke "tab"
			
		end repeat
	end tell
	
	
	
	beep
	--display dialog "Done adding " & numberOfNotes & " notes." buttons {"•"} default button 1 giving up after 3
	
end tell


on subSelectionOnPage(theSelection, thePage)
	tell application "Skim"
		-- normalize the selection
		join theSelection
		set theSubSelection to {}
		repeat with aSelectionRange in theSelection
			set aSelectionRange to {contents of aSelectionRange}
			if thePage = first item of (get pages for aSelectionRange) then
				set end of theSubSelection to aSelectionRange
			end if
		end repeat
		return theSubSelection
	end tell
end subSelectionOnPage


on chooseNoteType(typeList)
	tell application "Skim"
		set theResult to choose from list typeList with prompt "Note type:"
		if theResult is false then return 0
		set noteTypeString to theResult as string
		if noteTypeString is "Text Note" then
			return text note
		else if noteTypeString is "Anchored Note" then
			return anchored note
		else if noteTypeString is "Circle" then
			return circle note
		else if noteTypeString is "Box" then
			return box note
		else if noteTypeString is "Highlight" then
			return highlight note
		else if noteTypeString is "Highlight" then
			return highlight note
		else if noteTypeString is "Underline" then
			return underline note
		else if noteTypeString is "Strike Out" then
			return strike out note
		else if noteTypeString is "Line" then
			return line note
		else if noteTypeString is "Freehand" then
			set end of noteTypes to freehand note
		end if
	end tell
	return noteType
end chooseNoteType


some comments about the usage:

I’m still struggling to find a good workflow to sort my literature and sources for my phd thesis, so that I can find the right information in the right moment.
And as many of the papers and books will have to be used for writing several different chapters of my thesis, I had tagged them with “>NameOfChapter1.1” and/or “>NameOfChapter3.1” and so on.

But that also means that I always see the whole pdf in the filtered list for ChapterX.Y and don’t know what it contains.

Now I found a way for pointing to a certain content of the pdf by using the selected text in the pdf (a heading of a section or a phrase or a word) and creating a separate rtf note which will only contain the 1 or 2 tags for the concerned chapter.
(Surely I’ve added a short key Cmd-Opt-Y to invoke the script quickly.)

That seems better than the original approach…
… I’m currently testing. :slight_smile:

So for the workflow:
I then can search or filter for all rtf notes concerning the certain chapter or subsection when writing it and then can mark it as “100%used in thesis” with a tag.
The whole pdf I could not mark as used, as long as it would contain other interesting information…

My standard highlight color in skim is yellow, so the green highlights created by the script will show me that the information is linked to DTPro.

So I hope that solves my problem of missing overview…

what’s also missing:
It would be great if I could add “personal” notes or comments to the rtf directly, but using the “create rtf note” service, I can only change the title and the tags…

Maybe it’s useful for someone else - I’m looking forward to your comments.