Saturday, January 16, 2021

#1 2020-09-01 10:56:58 am

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 666
Website

Default browser name

Hi,
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 :
https://daringfireball.net/2009/01/appl … _or_webkit

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

Offline

 

#2 2020-09-01 05:43:34 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6549

Re: Default browser name

Try this:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2021-01-10 12:58:31 pm

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 666
Website

Re: Default browser name

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:

error "nsurl can't understand the message „URLWithString_“" number -1708 from nsurl


"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

Offline

 

#4 2021-01-10 02:46:51 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1537

Re: Default browser name

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

Applescript:


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


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#5 2021-01-10 04:59:41 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6549

Re: Default browser name

Joy wrote:

throws an error now:

error "nsurl can't understand the message „URLWithString_“" number -1708 from nsurl



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".


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#6 2021-01-12 08:22:06 am

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 666
Website

Re: Default browser name

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

/library/scriptingAdditions/

(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

@KniazidisR
I will test it later today, thanks

Offline

 

#7 2021-01-12 08:37:24 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 731

Re: Default browser name

Joy wrote:

Any suggestion is appreciated



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.


2018 Mac mini - macOS Catalina

Offline

 

#8 2021-01-12 08:53:45 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1537

Re: Default browser name

Joy wrote:

and yes, I have satimage.osax installed in

/library/scriptingAdditions/

(root lib)


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

Applescript:


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
       try
           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)

Last edited by KniazidisR (2021-01-12 08:57:13 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#9 2021-01-12 09:03:24 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11714
Website

Re: Default browser name

Joy wrote:

.. and yes, I have satimage.osax installed



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

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


regards

Stefan

Offline

 

#10 2021-01-13 05:21:14 am

Joy
Member
From:: South Tirol
Registered: 2008-07-04
Posts: 666
Website

Re: Default browser name

@KniazidisR
big_smile 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..

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)