AppleScript to get URL Name

Yesterday I created this AppleScript which runs from Hazel that takes a text file with 2 lines, first the name of the webpage and the second line is the URL, then creates a PDF in DEVONthink from that URL with the correct name.

I am wondering if there is a way to set the name based on the URL that is already being passed?

Thanks for any input and suggestions.

	set theFile to "Macintosh HD:Users:jcsullivan2:Library:Mobile Documents:iCloud~com~agiletortoise~Drafts5:Documents:Desktop:URL2PDF.txt"
	set paragraph_list to read file theFile using delimiter linefeed
	set theName to item 1 of paragraph_list
	set theURL to item 2 of paragraph_list
	tell application id "DNtp"
		set theRecord to create PDF document from theURL name theName pagination no
	end tell
end try

Could you provide an example URL and title as used by your script?

Sure, so currently the files contents would look like this:

Digital note taking

I’m hoping to avoid having to capture the Name in the file and have DTPO do it. DTPO can do it with the Clip to DEVONthink Save as PDF option, so hoping there is a way to do it.


Rereading what you’re doing, the create PDF document picks up the title automatically, so there’s nothing to fix. :smiley:

Okay, I read the AppleScript dictionary wrong, I thought the Name was a required parameter but only the URL is required.

Well that makes this much easier, thank you for pointing that out.

No problem.