macOSにはAppleScript(osascript)というスクリプト言語が使えます。そのAppleScriptのコマンドを使えば今開いているブラウザURLを取得することができます。AppleScript利用するには、ターミナルでosascriptコマンドを使います。
SafariのURLを取得するには下記のコードです。
osascript -e 'tell app "safari" to get the url of the current tab of window 1'
Google ChromeのURLを取得する場合
osascript -e 'tell app "google chrome" to get the url of the active tab of window 1'