|
| 1 | +-- SafriToDuckDuckGo.scpt |
| 2 | +-- |
| 3 | +-- A script to open the front Safari URL in DuckDuckGo. |
| 4 | +-- |
| 5 | +-- Copyright Anthony Arblaster 2025. |
| 6 | +-- – Web: https://codebyanthony.com |
| 7 | +-- – Mastodon: https://mastodonapp.uk/@aarblaster |
| 8 | +-- – GitHub: https://github.com/aarblaster |
| 9 | +-- |
| 10 | +-- MIT Licence |
| 11 | +-- Repo: https://github.com/aarblaster/UsefulAppleScripts |
| 12 | +-- |
| 13 | +-- Version 1.0 |
| 14 | +-- |
| 15 | + |
| 16 | +-- A Script to open the front tab in Safari in the DuckDuckGo browser. |
| 17 | +-- Requires that both browsers be installed. |
| 18 | +-- Trigger this script using any method you choose. |
| 19 | +-- I personally use Keyboard Maestro. |
| 20 | + |
| 21 | +if application "Safari" is running then |
| 22 | + tell application "Safari" |
| 23 | + set safariURL to URL of front document |
| 24 | + end tell |
| 25 | +else |
| 26 | + set safariURL to "https://www.abc.net.au/news" |
| 27 | +end if |
| 28 | + |
| 29 | +#Check if Firefox is already running |
| 30 | +if application "DuckDuckGo" is running then |
| 31 | + set duckWasRunning to true |
| 32 | +else |
| 33 | + set duckWasRunning to false |
| 34 | +end if |
| 35 | + |
| 36 | +-- Activate DuckDuckGo |
| 37 | +tell application "DuckDuckGo" to activate |
| 38 | + |
| 39 | +-- Check if DuckDuckGo was not running initially and there are open windows |
| 40 | +if not duckWasRunning then |
| 41 | + tell application "System Events" |
| 42 | + tell process "DuckDuckGo" |
| 43 | + if (count windows) is greater than 0 then |
| 44 | + # Close the front tab. |
| 45 | + keystroke "w" using {command down} |
| 46 | + #delay 1 # Add a delay to allow the tab to close |
| 47 | + end if |
| 48 | + end tell |
| 49 | + end tell |
| 50 | +end if |
| 51 | + |
| 52 | +-- Open the URL in Firefox |
| 53 | +tell application "DuckDuckGo" |
| 54 | + open location safariURL |
| 55 | +end tell |
| 56 | + |
0 commit comments