Sunday, December 4, 2022

#1 2022-11-01 11:44:28 am

akim
Member
Registered: 2010-04-04
Posts: 154

System preferences to change default browser

With Ventura 13.0, System Settings no longer allows an AppleScript command to reveal its general pane.


[AppleScript]
tell application "System Settings"
        reveal pane id "com.apple.preference.general"
[/appleScript]

I am interested in a new method of managing System Settings. My overall goal is to toggle System Settings' default browser. That current property or method in Ventura, is now displayed in the System Settings's window "Desktop & Dock". The pane function appears to be no longer viable in AppleScript.
The following command fails

[applescript]
tell application "System Settings"
    reveal pane "Desktop & Dock"
end tell
[/appleScript]

System Settings' pane and reveal pane functions remain in the dictionary for the application "System Settings", but do not appear functional. Perhaps relevant to this issue is that the dictionary's version for System Settings is listed as 15.0 and not 16.0.

In any case, I am interested in another method to script this application, although I  would much prefer a command line or other method  to change the System Setting's default browser.

Offline

 

#2 2022-11-01 03:06:44 pm

db123
Member
Registered: 2020-12-07
Posts: 65

Re: System preferences to change default browser

Use this:

Applescript:


use framework "Foundation"
use framework "AppKit"
use scripting additions

current application's NSWorkspace's sharedWorkspace()'s openURL:(current application's NSURL's URLWithString:"x-apple.systempreferences:com.apple.systempreferences.GeneralSettings")

You can find the paths in the file: /System/Applications/System Settings.app/Contents/Resources/Sidebar.plist

Offline

 

#3 2022-11-01 04:54:01 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 1091

Re: System preferences to change default browser

Its also possible at least it was on older macOS and Ventura to hard link to a .pref file
and open it with open command. I did a fast test on VM of Ventura

do shell script "open " & "/System/Library/PreferencePanes/Displays.prefPane"

This script do not work in Ventura 13.1

Applescript:

tell application "System Settings"
   tell every pane to its id
end tell

But it does in Monterey

Last edited by Fredrik71 (2022-11-01 04:55:12 pm)


Node-RED makes it easy to automate IoT

Offline

 

#4 2022-11-01 11:41:37 pm

akim
Member
Registered: 2010-04-04
Posts: 154

Re: System preferences to change default browser

Using db123's recommendation, I was able to script Ventura 13.0 to reveal its Desktop & Dock window in System Settings, so that I could toggle the default browser value between Safari and Google Chrome.

(Unrelated to this AppleScript problem, but related to this post, I was unable to style the following script using the AppleScript brackets. I have submitted my script, nonetheless.
I have now corrected the styling issue,  thanks to Mockman's kind input on using only lowercase text designating applescript in opening and closing brackets)

Applescript:


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

#    open System Settings window displaying Desktop & Dock settings, using db123's method
current application's NSWorkspace's sharedWorkspace()'s openURL:(current application's NSURL's URLWithString:"x-apple.systempreferences:com.apple.Desktop-Settings.extension")

tell application "System Settings"
   #    delay until System Settings' window displaying Desktop & Dock actually exists
   repeat until exists window "Desktop & Dock"
       delay 0.2
   end repeat
end tell

tell application "System Events"
   tell process "System Settings"
       tell window "Desktop & Dock"
           
           #    Formulate path to "Default web browser" pop up button
           set AHostingViewGroup to first group
           set AXSplitGroup1 to first splitter group of AHostingViewGroup
           set ScrollArea to scroll area 1 of group 1 of group 2 of AXSplitGroup1
           set DefaultWebBrowserPopUpButton to first pop up button of (group 7 of ScrollArea) whose name is "Default web browser"
           
           #    Set up boolean condition to toggle default web browser values between "Safari" and "Google Chrome
           tell DefaultWebBrowserPopUpButton
               if its value is "
Google Chrome" then
                   set AlternateBrowserValue to "
Safari"
               else
                   set AlternateBrowserValue to "
Google Chrome"
               end if
               
               click # to activate drop down menu
               repeat with i from 1 to 20
                   #    wait for pop up menu to be displayed
                   if exists menu 1 then
                       set PopUpMenuExists to true
                   end if
                   exit repeat
                   if i is 10 then
                       set PopUpMenuExists to false
                   end if
                   delay 0.2
               end repeat
               if PopUpMenuExists is true then
                   tell menu 1
                       click (first menu item whose title is AlternateBrowserValue)
                   end tell
               end if
           end tell
           
           click (first button whose description is "
close button")
       end tell
       
   end tell
end tell

if PopUpMenuExists is false then
   display dialog "
Pop Up Menu failed to display" giving up after 2
else
   display dialog AlternateBrowserValue with title "
New Default Browser" giving up after 2
end if

As the UI scripting was tedious, I would enjoy learning whether either a command line or AppleScript- Objective C method exists to toggle between default browser values.

Last edited by akim (2022-11-04 08:50:17 am)

Offline

 

#5 2022-11-02 10:49:51 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 267

Re: System preferences to change default browser

akim wrote:

(Unrelated to this AppleScript problem, but related to this post, I was unable to style the following script using the AppleScript brackets…

The tags should be all lowercase… 

'applescript', not 'AppleScript'

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)