simple script to capture pdf file in current browser window.

hey all,

for some dumb reason, it took me quite a while to figure out what I was doing wrong to make this script not work, but now it does. It allieviates one of my pet peeves with all browsers under tiger: the fact that the webkit pdf takes over the display of pdfs (which is nice), but that it then becomes a four step process to save a pdf currently being viewed (which is not so nice). This little script figures captures the current url being browsed in devonthink pro, and assuming it is a pdf file, it will capture it and save it to the current folder. Obviously the code can be modified or put with other scripts, but I like the stand alone behavior, because one can tie it to a control key, press the key, and voila, a one-key pdf save. Just thought I’d share! The incredible scriptablity of dtpro makes it an incredible program.



---This script saves the pdf currently selected in a browser window into the current folder

tell application "DEVONthink Pro"
	set theURL to URL of window 1
	set cuPos to selection of window 1
	if cuPos is not {} then
		if kind of item 1 of cuPos is "Group" then
			set import_location to first item of cuPos
		else if parent of item 1 of cuPos is not {} then
			set import_location to first item of parent of item 1 of cuPos
			set import_location to root of current database
		end if
	else --current position is root
		set import_location to root of current database
	end if
		---uncomment the line below line to put new pdfs in a special folder on the root instead of the current folder 
		--set import_location to (get record at "/file elsewhere" in current database)
	set z to download URL theURL
	set html_record to create record with {name:"rename-me", type:picture, URL:theURL} in import_location
	set data of html_record to z
end tell

‘:D’ Thanks a lot, Erico, very elegant and useful ! ‘:D’


Warning: Due to a bug of DT Pro, this does not index the PDF document (which is therefore not searchable and treated as an image). The next beta of DT Pro 1.1 will fix this.