Applescript 打开镜像并选择 iPad

问题描述 投票:0回答:2

我最近将我的 mac 更新到了蒙特利,我的旧 applescript 不再工作,我收到此错误:“系统事件发生错误:无法获取进程“系统偏好设置”窗口 1 的弹出按钮 1。索引无效。'

老实说我不知道我应该改变哪一部分。预先感谢您。

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

tell application "System Events"
    tell process "System Preferences"
        
        click pop up button 1 of window 1
        click menu item 1 of menu 1 of pop up button 1 of window 1
    end tell
end tell

tell application "System Preferences"
    delay 10
    quit
end tell

applescript macos-monterey
2个回答
0
投票
tell application "System Preferences"
    reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays"
    activate
end tell

tell application "System Events"
    tell application process "System Preferences"
        click pop up button "Add Display" of window "Displays"
        click menu item 2 of menu 1 of pop up button "Add Display" of window "Displays"
    end tell
end tell

tell application "System Preferences"
    delay 5
    quit
end tell

0
投票

这对我在 Sonoma 14.2.1 上有效。需要注意的是,它可以在 AppleScript 中运行,并且可以在快捷方式编辑器面板上运行。但是,当直接从快捷方式小部件运行它时,它无法专注于“设置”页面并继续。更擅长 AppleScripts 的人应该能够完成此任务!

YT 上的这个教程很有帮助。

tell application "System Settings"
    activate
    reveal pane id "com.apple.Displays-Settings.extension"
    delay 2.0
end tell

tell application "System Events"
    tell window 1 of application process "System Settings"
        tell pop up button "Add" of group 1 of group 2 of splitter group 1 of group 1
            click
            delay 1.0
            keystroke "I"
            keystroke "P"
            keystroke "A"
            keystroke "D"
            keystroke return
        end tell
    end tell
end tell
© www.soinside.com 2019 - 2024. All rights reserved.