Useful AppleScripts v1.0.1

There’s a new update to the UsefulAppleScripts repo on GitHub. It’s an all new and fancy version 1.0.1. The changes are really minor and mostly just introduce a new script that I have been using to open Safari pages in DuckDuckGo. Mostly I only use this if Safari isn’t rendering a page correctly, or a webform is being dumb.

You can download the zipped file or an individual file on Github. You can also read my original post about this collection of scripts here.

The AppleScript I have added isn’t very complex. It takes the front tab in Safari, check if DuckDuckGo is already open, and then opens the link in DuckDuckGo. It makes some allowances for the fact that when you open DuckDuckGo via AppleScript it will open a new tab. The script closes this extra tab, unless DuckDuckGo is already running. This stops you accidentally closing a tab you wanted!

-- SafriToDuckDuckGo.scpt
--
-- A script to open the front Safari URL in DuckDuckGo.
--
-- Copyright Anthony Arblaster 2025.
--    – Web: https://codebyanthony.com
--    – Mastodon: https://mastodonapp.uk/@aarblaster
--    – GitHub: https://github.com/aarblaster
--
-- MIT Licence
-- Repo: https://github.com/aarblaster/UsefulAppleScripts
--
-- Version 1.0
--

-- A Script to open the front tab in Safari in the DuckDuckGo browser.
-- Requires that both browsers be installed.
-- Trigger this script using any method you choose.
-- I personally use Keyboard Maestro.

if application "Safari" is running then
	tell application "Safari"
		set safariURL to URL of front document
	end tell
else
	set safariURL to "https://www.abc.net.au/news"
end if

#Check if DuckDuckGo is already running
if application "DuckDuckGo" is running then
	set duckWasRunning to true
else
	set duckWasRunning to false
end if

-- Activate DuckDuckGo
tell application "DuckDuckGo" to activate

-- Check if DuckDuckGo was not running initially and there are open windows
if not duckWasRunning then
	tell application "System Events"
		tell process "DuckDuckGo"
			if (count windows) is greater than 0 then
				# Close the front tab.
				keystroke "w" using {command down}
				#delay 1 # Add a delay to allow the tab to close
			end if
		end tell
	end tell
end if

-- Open the URL in Firefox
tell application "DuckDuckGo"
	open location safariURL
end tell

Like everything else in this repository it’s covered by the MIT Licence, so you can make use of it as you wish. To download the script just pop over to GitHub and download the zipped v1.0.1 release.

Happy scripting.