Dash get address script

Hi everyone, I hope you’re all well.

Please find below a Get Address script for Dash, the documentation browser.

Unfortunately Dash is not scriptable, so this is relatively crude. Similar to the included scripts for other non-scriptable applications, it uses System Events to execute the ⌥⌘B “Copy Online Page URL” shortcut.

An additional wrinkle is that Dash initially sets the clipboard to a https://kapeli.com/dash_share?… URL, presumably so that links to online documentation can be kept up to date. Dash then appears to set the clipboard to the real documentation URL once that redirect has resolved.

This is the reason for the loop containing a delay. I’ve set a fairly large number of checks and a fairly short delay duration by default, but you may want to change these if you’re regularly getting the redirect URLs.

set maxChecks to 50 -- Maximum number of checks.
set delayDuration to 0.005 -- Maximum between-check pause in seconds.

set the clipboard to ""
tell application "System Events"
	keystroke "b" using {command down, option down}
	set link to ""
	repeat maxChecks times
			set link to (the clipboard as text)
		on error
			-- I think errors occur if the clipboard is checked while
			-- Dash is replacing its redirect with the real link.
		end try
		if not (link starts with "https://kapeli.com/" or link is "") then
			-- Clipboard set to real documentation link.
			exit repeat
		end if
		-- Clipboard is redirect link, empty or unreadable.
		delay delayDuration
	end repeat
	return link
end tell
1 Like