RFE: Rename > To Web Page Title for web archive clips

I frequently use the Capture Web Archive (Command-%) service to save web archive clips and often want the DT document name to be the same as the original web page title. Could the Script Menu > Rename > To Web Page Title script be enhanced to successfully rename those web archive clips? Or, maybe a new script or other method could provide that capability? Whatever can reduce the amount of manual copy/paste renaming I’m doing would be appreciated – thanks!

Seconded. I sometimes get document names plucked from random text on the clipped web page.

If I understand what you are saying here, this is really easy.

I just added the phrase “or this_type is equal to webarchive” to the line that begins “if this_type is equal to html”

If I’m not mistaken, the date on the script predates devonthink support for webarchives!

At any rate, this change works for me…please tell me if I got it wrong…

I would highly recommend sticking the bit onto the end of the file name that allows you to execute this with a keystroke. (I use ___Ctrl-Alt-R at the end of this script file, so I can rename with a single key combination. )

-erico


-- Set name to title of Web page
-- Created by Christian Grunenberg Mon Apr 26 2004.
-- Copyright (c) 2004-2009. All rights reserved.

tell application id "com.devon-technologies.thinkpro2"
	try
		set this_selection to the selection
		set this_count to count of this_selection
		if this_count > 0 then
			show progress indicator "Renaming" steps this_count
			repeat with this_item in this_selection
				set this_type to the type of this_item
				step progress indicator (name of this_item) as string
				if this_type is equal to html or this_type is equal to webarchive then
					set this_URL to the URL of this_item
					set this_source to source of this_item
					if this_source is not missing value then
						set this_title to get title of this_source
						if this_title is not missing value and this_title is not "" then set the name of this_item to this_title
					end if
				else if this_type is equal to bookmark then
					set this_URL to the URL of this_item
					if this_URL is not "" then
						set this_source to download markup from this_URL
						if this_source is not missing value then
							set this_title to get title of this_source
							if this_title is not missing value and this_title is not "" then set the name of this_item to this_title
						end if
					end if
				end if
			end repeat
			hide progress indicator
		end if
	on error error_message number error_number
		hide progress indicator
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell



I can’t get it working, though maybe I’ve goofed. I inserted the “or … webarchive” string in the original file, saved it, and relaunched DTPO. Script runs but the document name doesn’t change. It didn’t work with a Web Archive document to HTML either. I think it’s because there’s no tag in either document. When missing (e.g. with Capture Web Archive service clips), wouldn’t the script need to attempt getting titles from sites using document URLs?

And here’s something that’s been begging to be answered for awhile:

Why do the filenames of the script files differ from the names displayed under the script menu? In this case, Set Name To Title Of Web Page.scpt is the filename but it’s To Web Page Title under the menu. I can’t find any mapping between the two. Maybe the leading '’ (underscore) filename prefix has something to do with it? Like most things AppleScript this seems obscure to me.

Through Private message I came to understand better what sjk wanted here—which was not the ability to pull the tag from a webarchive of the full page, but to go out on the internet and capture the title tag from the full webpage when only a segment of it had been clipped via the services command. I had never thought of doing this, but it’s actually tremendously useful.

So below is the script that will do this for you.

As for the file name trick: the script menu in devonthink can set up scripts to execute with a keystroke if the script filename is appended with three underlines and then the key-combination. Some scripts additionally have an underscore in the front of them, which is used (I think) to insert dividers in the script menu.

please report any trouble here. otherwise, enjoy…
-e


---fetch title from website recorded in the URL field
---- by eric oberle
---v .3
---named as Retitle From URL___Ctrl-Alt-R  so as to be easy to execute from keystroke

using terms from application "DEVONthink Pro"
	tell application "DEVONthink Pro"
		try
			set this_selection to the selection
			repeat with this_item in this_selection
				set this_type to the type of this_item
				set this_url to the URL of this_item
				if this_url is not "" then
					set this_source to download markup from this_url
					set this_title to get title of this_source
					
					if this_title is not missing value and this_title is not "" then set the name of this_item to this_title
				else
					display dialog "There's no url supplied for this file "
					return
				end if
				
			end repeat
		on error error_message number error_number
			if the error_number is not -128 then
				display dialog error_message buttons {"OK"} default button 1
			end if
		end try
	end tell
end using terms from



The service worked initially that way but people requested it to work like the other services and therefore it’s now using the beginning of the clipping to name the new document. However, if DEVONthink Pro’s “Select group” option is enabled, then you’re able to enter the name on your own since 2.0pb7.

At one point the Capture Web Archive service used the page URL, never it’s title, as the DT document name and I’m one of the people who wanted that be changed:

REQ: sane titles for Capture Web Archive (Services menu)

And I still prefer documents created with services be named that way instead of using page URLs.

That’s fine if/when I want to enter names that way. But my suggestion was heavily influenced by wanting to reduce the effort of manually (re)naming documents.

erico’s script fulfills that, for doing page title-based document renaming as I’d previously wanted at least the Capture Web Archive service to do directly. And it’s not limited to just web archives; it’s a generalized replacement for the “Rename > To Web Page Title” script and it limitations.