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?
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
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
My fault, itās actually not part of the latest releases anymore as thereās now a āCheck Bookmarkā action. This action is a lot faster than the script and performed in the background.
the help docs say of that Action ā¦Check Bookmarks: Checks the URL of the matched items. Any issues with the URL are reported in the Log window or the Log popoverā¦. what exactly does that do? Anything similar to the above-mentioned scriptās ā„ 400 and 403 but neither 405 yet neither 404 nor containing 'github.com/' etc? I added āDisplay alertā steps both before and after checking and they display almost instantaneouslyā¦ does āCheck Bookmarksā actually perform HTTP validation?
is there a way to run such validation on webarchives?
But for #2 (webarchives), Iām a little puzzled: I have a webarchive (in DT 3.7) whose correct URL is https://www.alamy.com. If I change the URL (in DT) to https://www.alamx.com (replace the final āyā with an āxā) in Safari I get a 404 of course.
In DT I created a Smart Group (not necessary as I also do that in the Smart Rule itself) to look for any URLs containing āalamxā (āKind is Web Archiveā + āURL contains alamxā).