Get default web browser and mail client?

Anybody know of a script to get someone’s default web browser and mail client? I searched around on this site a bit, but I couldn’t find a script that works on my mac.

Any help is appreciated :slight_smile:

Model: MacBook Pro
AppleScript: 2.1.2
Operating System: Mac OS X (10.6)

hello,

path to the browser:

set x to do shell script "defaults read com.apple.LaunchServices | grep 'http;' | cut -d \\\" -f 2"
tell application "Finder" to application file id x as alias

path the mail client:

set x to do shell script "defaults read com.apple.LaunchServices | grep 'mailto' | cut -d \\\" -f 2"
tell application "Finder" to application file id x as alias

Both of those compile but get a Finder error on my machines (10.5.8 or 10.6.3)

Finder got an error: An error of type -10814 has occurred.

Sorry Adam, I tested my script on my old 10.4.11

Hi,

in Leopard and higher com.apple.LaunchServices.plist has a slightly different structure.
This is a reliable handler for > 10.4 to retrieve the default browser and mail client.
It considers also a missing entry for http, that’s the status, if the default browser has never been changed


tell application "Finder" to set defaultBrowser to application file id (my default_service("http")) as alias
tell application "Finder" to set defaultMailClient to application file id (my default_service("mailto")) as alias

on default_service(p)
	tell (system attribute "sysv") to set MacOS_version to it mod 4096 div 16
	if MacOS_version < 5 then
		set {a1, a2} to {2, 1}
	else
		set {a1, a2} to {1, 2}
	end if
	set pListpath to (path to preferences as Unicode text) & "com.apple.LaunchServices.plist"
	tell application "System Events"
		repeat with i in property list items of property list item 1 of contents of property list file pListpath
			if value of property list item a2 of i is p then
				return value of property list item a1 of i
			end if
		end repeat
		if p is "http" then
			return "com.apple.Safari"
		else if p is "mailto" then
			return "com.apple.Mail"
		else
			return ""
		end if
	end tell
end default_service

Thanks very much for that Stefan. The default mail client works, but default browser doesn’t :frowning: Also, how would I use this in ASOC?