You are not logged in.
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
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
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
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
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
@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
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
and yes, I have satimage.osax installed in
/library/scriptingAdditions/
(root lib)
It may be installed in other locations too (and forgotten there ). 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
.. 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
@KniazidisR 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