snippets clipper script

Dear all,

Here’s a simple little script I wrote that many of you might find helpful. It is a text snippet script that is designed to be set on a universal hot key. Then when you run the script, it searches devon-think and looks for text files with the word “clip-file” in their name. It finds the most recently modified of these, and pastes the text currently in the clipboard into the bottom of that file. In other words, you can have as many clip-file (s) as you wish, and you just “select” the one you want as a destination by going into devon think clicking on the file, adding a space and deleting it, or (using the ‘touch’ script), and then go do your thing with your word processor, browser, even with devonthink, copying text into the clipboard, and then running the script, and it wil put each clipping into the “newest” file with “clip-file” in its name. Simple and easily extensible, but thought I’d put it up in case it would be useful. In many ways, these kind of little scripts show the power of devonthink more than anything else, in my opinion. This wouldn’t work if dtpro weren’t fast as well as scriptable, and it works nicely (again, IMHO) best because it never brings dtpro to the foreground:

-erico



tell application "System Events"
--the next line removes all formatting if uncommented
	---set the clipboard to «class ktxt» of ((the clipboard as text) as record)
	set the_clip to the clipboard ---as text
       set old_date to date "Thursday, January 1, 2004 12:00:00 AM"

end tell


tell application "DEVONthink Pro"
	set state_set to search "clip-file" within titles
	set newest_record to first item in state_set
        --look for the newest one
	repeat with the_record in state_set
		get name of the_record
		set new_date to get modification date of the_record

		if (new_date > old_date) then
			log "date change"
			set newest_record to the_record
			set old_date to new_date
		end if
	end repeat
	
	get name of newest_record
	
	set x to rich text of newest_record
	set x to x & return & "--------------------" & return & (the_clip as styled text)
	set rich text of newest_record to x
end tell


Interesting script and nice idea. :slight_smile:

This could be very useful.

thank you!

I had a request for a quicksilver version of this script. I hope this is useful as well; instructions in the header of the script…

-erico



-----quicksilver clipper file script for Devonthink Pro appends the current text in the clipboard to the most recently
------modified Devonthink text file that contains in its title the phrase that you enter into quicksilver
-----To Install: name this script  "Devonthink quick clip" (or something like that) 
-----and place it in ~/Library/Application Support/Quicksilver/
-----To use: invoke quicksilver.  
-----Press Period (.) 
------Type in text belonging to a text file in devonthink (e.g. applescript;baseball;philosophy, etc.)
-----Hit tab, then type in a phrase that finds this script in qs (I use "dqq", but you can set your favorite using the contextual menu in Quicksilver)
------Hit return, and the clipboard should be saved without bringing DT to the foreground.


using terms from application "Quicksilver"
	on process text t
		tell application "System Events"
			---set the clipboard to «class ktxt» of ((the clipboard as text) as record)
			set the_clip to the clipboard ---as text
			set old_date to date "Thursday, January 1, 2004 12:00:00 AM"
		end tell
		
		tell application "DEVONthink Pro"
			set state_set to search t within titles
			if state_set is {} then
				tell application "System Events"
					display dialog "No records found named " & t & ".  Please check Devonthink and try again."
					
				end tell
			else
				set newest_record to first item in state_set
				repeat with the_record in state_set
					if type of the_record is not group then
						get name of the_record
						set new_date to get modification date of the_record
						---set state of the_record to false
						if (new_date > old_date) then
							log "date change"
							set newest_record to the_record
							set old_date to new_date
						end if
					end if
				end repeat
				
				get name of newest_record
				
				log message "Clip " & (name of newest_record) & " added: " & the_clip
				----should put this on growl
				----display dialog z
				set x to rich text of newest_record
				set x to x & return & "--------------------" & return & (the_clip as styled text)
				set rich text of newest_record to x
			end if
		end tell
		
	end process text
end using terms from