find dead links

Is there a way to find (and thus delete) dead links?

I have a bookmark file in Devonthink and it is dead (the website no longer exists). There are many such files in DTPro and I am wondering if there is a way to search for bookmarks (or any link) that is dead?

Thank you.

It’s not possible to search for them but a script can verify them. The following script replicates invalidate bookmarks to a group named “Invalid URLs”. In addition, both invalid and updated bookmarks are logged to Windows > Log. However, depending on the number of bookmarks this might require some time.


tell application id "DNtp"
	set theRecords to (contents of current database whose type is bookmark)
	if (count of theRecords) > 0 then
		show progress indicator "Checking Links…" steps (count of theRecords) with cancel button
		try
			repeat with theRecord in theRecords
				set theURL to (URL of theRecord)
				step progress indicator ((name of theRecord) as string)
				if theURL begins with "http" and theURL contains "://" then
					set theStatus to 0
					download URL theURL method "HEAD"
					try
						set theResponse to last downloaded response
						set theStatus to |http-status| of theResponse
						if theStatus ≤ 0 or (theStatus ≥ 400 and theStatus is not 403 and theStatus is not 405 and (theStatus is not 404 or theURL does not contain "github.com/")) then error
						set theDownloadedURL to last downloaded URL
						if theURL is not equal to theDownloadedURL then
							set URL of theRecord to theDownloadedURL
							log message theURL info "Updated URL (" & theDownloadedURL & ")"
						end if
					on error
						log message theURL info "Invalid URL (HTTP " & (theStatus as string) & ")"
						set theGroup to create location "/Invalid URLs" in (database of theRecord)
						replicate record theRecord to theGroup
					end try
				end if
				if cancelled progress then exit repeat
			end repeat
		on error error_message number error_number
			if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
		end try
		hide progress indicator
	end if
end tell

Thank you!

Now one more question if you have a moment.

How would I delete the original and the replicant?

By the way, did you create this recently or was this something you already had?

Just select the item and choose Data > Move All Instances to Trash (accessible while holding the Alt modifier key) or press its shortcut.

It’s based on a similar script I’ve been using for some time now.

Fantastic script! Thanks for sharing.

Ok, I’m on shaky ground here and I need a little guidance. I created the script and it is working. Where are the broken links? Where are they located or how do I identify them? Thanks

Never mind… I just found the “Invalid URL” group - thanks very much…

Nice gem.
Thanks @cgrunenberg!
Made it a Smart Rule on a weekly basis and added flagging to broken bookmarks
A “musthave” script

DEVONthink 3 include already a similar script for smart rules, see action Execute Script > External > Check Links.

1 Like