Determine default browser, email client

I have older code that could determine the default browser. This code read the defaults for com.apple.LaunchServices. Under Sonoma ( possibly earlier as well ) this is no longer viable.

Is there a modern, reliable method for determining default apps for http, email etc?

You can use this (written with no concern for elegancy):

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

set ca to current application
set nsws to ca's NSWorkspace
set sws to nsws's sharedWorkspace

set appURL to sws's URLForApplicationToOpenURL:(ca's NSURL's URLWithString:"https://apple.com")
appURL's |path| as string

It’s quite possible that easier ways are also available.

1 Like

Thanks Leo_r, I think it’s elegant.

I’m now unsuccessfully trying to modify this to use URLsForApplicationsToOpenContentType.

By the way you can still use this even on Sequoia beta:

defaults read ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure