Default browser name

I was wondering if it’s possible to get the name of the default browser straight with an applescript.

Online you’ll find a perl script :

But I’d like to do it without perl, because the perl alternative script fails sometimes, I don’t know why

Try this:

use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use framework "AppKit"
use scripting additions

set theURL to current application's NSWorkspace's sharedWorkspace()'s URLForApplicationToOpenURL:(current application's NSURL's URLWithString:"http://")
return theURL's |path|() as string

these days i had to reinstall my system from a recent backup and now some of scripts behave strangely,
if i execute your code you posted above (which worked perfectly fine before) then Script Editor throws an error now:

"can’t understand the message " is my translation, as this piece of the error message is written in German
My Disk was obviously formatted as a Guid partition table, Journaling is active and uppercase/lowercase’s are ignored. What is missing to mess up these scripts?

i updated my MacOs with a security patch but these changes did not affect my scripts behavior, and i do not know yet how much more code misbehaves or does not work anymore as usual. Maybe my system needs to run for some days to get back on track? some update procedures take time and happen in the background.
Any suggestion is appreciated,
Happy new 2021, to all

AsObjC solution works fine on my Mac and is about 7 times faster than following plain AppleScript solution I found on the net:

do shell script "defaults read ~/Library/Preferences/ | awk -F'\"' '/http;/{print window[(NR)-1]}{window[NR]=$2}'"

You don’t say what version of the OS you are using, but that sounds like a conflict with Satimage.osax. Try changing “NSURL’s” to “|NSURL|'s”.

I apologize for my omission. My system is running macOS 10.14.6 (Mojave) and yes, I have satimage.osax installed in

(root lib)

But there are also Fits.osax, numerics.osax and xmllib.osax, these plugins were installed together with Satimage.osax if i remember well.

However, these osax were already there before, so I wonder what may have caused the moody change of my scripts right now ? If it wouldn’t be this annoyance I’d laugh about

I tried with pipe, the error dialog didn’t change. I removed the satimage.osax, I can restart my computer later. Let’s try again

I will test it later today, thanks

I’m new to ASObjC but I always seem to get those don’t understand error messages when a required use-framework statement is not present in the script. Anyways, something to check FWIW.

It may be installed in other locations too (and forgotten there :smiley: ). The following script helps to check if some certain scripting addition is installed on your Mac.

on scriptingAdditionExists(_name)
	set locScptAddFldr to path to scripting additions from local domain as text
	set sysScptAddFldr to path to scripting additions from system domain as text
	set usrScptAddFldr to path to scripting additions from user domain as text
	set saLocList to {locScptAddFldr, sysScptAddFldr, usrScptAddFldr}
	repeat with i in saLocList
			alias (i & _name)
			return true
		end try
	end repeat
	return false
end scriptingAdditionExists

my scriptingAdditionExists("Satimage.osax")

Note: you can check other scripting additions as well (by its names)

In Mojave and later third party scripting additions are not supported anymore.

For the SatImage.osax there is a replacement provided by Mark Alldritt

:smiley: thanks, I removed all scripting extensions.
Your shell does a nice job. Still, I’m puzzled why AsObjC doesn’t work as expected

I tried to run again the original script from Shane, then adding the pipe as suggested… Hmm, no change.
I must have a strange macpro, everything is from Apple except the mouse and the screen. I didn’t expect those machines to be able to learn stubbornness from their users…

Try to find the exact cause of the error by breaking the AsObjC code like this:

Also, as I see from the documentation, the URLWithString method expects an NSString as its parameter, not a String. On Catalina this does not cause an error, but it would be more correct (for everyone):

-- script: Determine Default Browser (its Posix path, ID, name)
-- created by Shane Stanley, thanks. Edited by me. 

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

set NSWorkspace to a reference to NSWorkspace of current application
set sharedWorkspace to sharedWorkspace() of NSWorkspace
set |NSURL| to a reference to |NSURL| of current application
set urlNSString to (current application's NSString)'s stringWithString:"http://" -- EDITED
set testURL to |NSURL|'s URLWithString:urlNSString -- EDITED
set theURL to sharedWorkspace()'s URLForApplicationToOpenURL:testURL

set defaultBrowserPosixPath to theURL's |path|() as string
set defaultBrowserID to id of application defaultBrowserPosixPath
set defaultBrowserName to name of application defaultBrowserPosixPath

return {defaultBrowserPosixPath:defaultBrowserPosixPath, defaultBrowserID:defaultBrowserID, defaultBrowserName:defaultBrowserName}

@ KniazidisR

thanks for your code, it works like a charm !
Personally i am not very fond of Apple’s developer documentation, or coding books, maybe its just me reading too much stuff overall. Anyway, i appreciate