Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何访问applescript无法访问的UI?_Objective C_Xcode_Macos_Applescript - Fatal编程技术网

Objective c 如何访问applescript无法访问的UI?

Objective c 如何访问applescript无法访问的UI?,objective-c,xcode,macos,applescript,Objective C,Xcode,Macos,Applescript,我正在寻找访问applescript无法访问的UI的方法。我知道applescript可以访问UI元素。但有时我会遇到无法通过applescript访问UI元素的情况。就像下面 tell application "System Preferences" to activate delay 1 tell application "System Events" tell process "System Preferences" set frontmost to true

我正在寻找访问applescript无法访问的UI的方法。我知道applescript可以访问UI元素。但有时我会遇到无法通过applescript访问UI元素的情况。就像下面

tell application "System Preferences" to activate
delay 1
tell application "System Events"
    tell process "System Preferences"
        set frontmost to true
        click button 22 of scroll area 1 of window 1
        delay 1
        UI elements of last group of list 1 of window 1
    end tell
end tell
这只返回2个UI元素图像静态文本

{
image 1 of group 3 of list 1 of window "Users & Groups" of application process "System Preferences" of application "System Events",
static text "Login Options" of group 3 of list 1 of window "Users & Groups" of application process "System Preferences" of application "System Events"
}
显然,有一个可点击的UI元素,它包含两个以上的元素。因为我可以点击“登录选项”

幸运的是,通过发送按键笔划按键代码命令,可以正确接收命令

set DownArrow to 125
set UpArrow to 126
tell application "System Preferences" to activate
delay 1
tell application "System Events"
    tell process "System Preferences"
        set frontmost to true
        click button 22 of scroll area 1 of window 1
        delay 1
        keystroke tab
        repeat 3 times
            delay 1
            key code DownArrow
            delay 1
            key code UpArrow
        end repeat
    end tell
end tell
tell application "System Preferences" to quit
我的问题是

  • 为什么applescript似乎忽略了“登录选项”UI元素
  • 为什么我不能用鼠标或触摸板单击“登录选项”UI元素
  • 为什么键笔划键代码命令不能访问“登录选项”UI元素
  • 如果不使用按键笔划按键代码命令,是否真的无法选择“登录选项”UI元素
  • 如何访问applescript不可访问的UI元素
任何暗示都将不胜感激。任何代码(python、c、objective-c等)都更受欢迎。:)


谢谢。

您可以像使用系统首选项时那样直接模拟CLIC,但您需要知道要单击哪个对象。 仅供参考,这里是一个系统首选项的示例,单击并选择蓝牙。它给出了一种方法:

tell application "System Preferences"
activate
set current pane to pane "com.apple.preferences.Bluetooth"
tell application "System Events"
    tell process "System Preferences"
        -- select row containing the word "mouse"
        repeat with I from 1 to count of row of table 1 of scroll area 2 of group 1 of front window
            set Nom_Perif to (description of static text 1 of row I of table 1 of scroll area 2 of group 1 of front window) as string
            if Nom_Perif contains "Mouse" then
                set selected of row I of table 1 of scroll area 2 of group 1 of front window to true
                if Nom_Perif contains "not connected" then
                    -- sert connection  via item 1 of menu
                    click menu button of group 1 of front window
                    delay 1
                    click menu item "Connect" of menu of menu button of group 1 of front window
                    delay 3
                end if
            end if
        end repeat
    end tell
end tell
end tell
quit application "System Preferences"

要解决其中许多问题,您不需要系统事件。例如,系统首选项的脚本能力足以至少做到这一点,这解决了您的一些问题:

tell application "System Preferences"
    activate
    set the current pane to pane id "com.apple.preferences.users"
    reveal anchor "loginOptionsPref" of current pane
end tell
所以

  • AppleScript没有“忽略”登录选项控件
  • 你不需要点击,你可以使用“显示”(你的意思是键入“不能”而不是“可以”?——我已经编辑了你的帖子,使你的问题格式更正确)
  • 我认为这使得第三个问题变得毫无意义
  • 我的示例显示了不单击的方法
  • 如何访问“不可访问”项--更大的问题:
  • 虽然系统首选项确实是可以编写脚本的,但有时您可能需要系统事件。例如,我有一个声音窗格脚本,它使用以下处理程序(子例程):

    ,我可以通过执行来使用,例如:

    doSysEvSelect("Internal Microphone", "Sound")
    
    使用系统事件可能会令人沮丧。当然,我们可以找到很多例子。如果你真的陷入困境,你可以使用Sikuli()来自动化任何事情,但这完全依赖于用户界面和点击

    [编辑]

    下面是一个示例,说明在登录选项中的一个项目出现后如何处理(这是您需要使用系统事件的地方):


    请注意,要找到正确的锚点名称,可以执行诸如当前窗格的锚点名称之类的操作。
    doSysEvSelect("Internal Microphone", "Sound")
    
    tell application "System Events"
        tell process "System Preferences"
            if value of checkbox "Show password hints" of group 1 of window "Users & Groups" is 0 then
                click checkbox "Show password hints" of group 1 of window "Users & Groups"
            end if
        end tell
    end tell