0

我正在尝试编写一个applescript来更改系统偏好设置中的热点设置。

系统偏好设置、桌面和屏幕保护程序窗格

这是我到目前为止所得到的。

tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.desktopscreeneffect"
end tell

tell application "System Events"
    tell process "System Preferences"
        click button "Hot Corners..."
    end tell
end tell

但我得到这个错误:error "System Events got an error: Can’t get button \"Hot Corners...\" of process \"System Preferences\"." number -1728 from button "Hot Corners..." of process "System Preferences"。我会很感激有人解释这里出了什么问题,还有没有办法获取窗格的属性(例如可用按钮)?

4

2 回答 2

1
于 2021-02-25T19:28:30.593 回答
1

如果您在问题中提到要选择热门角落中的哪个下拉菜单……我可以在我的解决方案中发布该附加代码。

此 AppleScript 代码适用于我使用最新版本的 macOS Big Sur。

(* Quits "System Preferences" If Running *)

if application "System Preferences" is running then ¬
    do shell script "killall 'System Preferences'"

(* Makes Sure "System Preferences" Is Not Running
Checking Every 1/10 Of A Second Before Moving On 
To The Next Command*)

repeat until application "System Preferences" is not running
    delay 0.1
end repeat

tell application "System Preferences"
    
    (* Launches "System Preferences" Without Bringing It
    To The Foreground, Going Directly To The Window Where You Can
    `click button "Hot Corners..."` *)
    
    reveal anchor "ScreenSaverPref_HotCorners" of ¬
        pane id "com.apple.preference.desktopscreeneffect"
    
    (* Makes Sure anchor "ScreenSaverPref_HotCorners" exists
    Checking Every 1/10 Of A Second Before Moving On 
    To The Next Command*)
    
    repeat while not (exists of anchor "ScreenSaverPref_HotCorners" of ¬
        pane id "com.apple.preference.desktopscreeneffect")
        delay 0.1
    end repeat
    
    (*.Makes application "System Preferences"
    The Frontmost Visible App, Allowing You To Perform
    Any Click Commands *)
    activate
end tell

delay 0.1
tell application "System Events"
    (* "Upper Left Dropdown Menu (pop up button 1) This Can Also Be Repeated
    For `(pop up button 2) <-- Bottom Left, (pop up button 3) <-- Upper Right,
     & (pop up button 4) <-- Bottom Right" *)
    
    (*. By Now You Should Start Understanding The Purpose And Function
     Of These Repeat Loops *)
    
    repeat while not (exists of pop up button 1 of group 1 of sheet 1 of window ¬
        "Desktop & Screen Saver" of application process "System Preferences")
        delay 0.1
    end repeat
    
    click pop up button 1 of group 1 of sheet 1 of window ¬
        "Desktop & Screen Saver" of application process "System Preferences"
    delay 0.1
    
    repeat while not (exists of menu item "Launchpad" of menu 1 of ¬
        pop up button 1 of group 1 of sheet 1 of window "Desktop & Screen Saver" of ¬
        application process "System Preferences")
        delay 0.1
    end repeat
    
    -- Replace "Launchpad" Which Which Ever You Want
    click menu item "Launchpad" of menu 1 of pop up button 1 of ¬
        group 1 of sheet 1 of window "Desktop & Screen Saver" of ¬
        application process "System Preferences"
    delay 0.3
    click UI element "OK" of sheet 1 of window ¬
        "Desktop & Screen Saver" of application process "System Preferences"
end tell
delay 0.5
tell application "System Preferences" to quit

在此处输入图像描述

于 2021-02-25T19:31:34.083 回答