2

我希望能够通过 Applescript 检查鼠标键的状态,以便脚本只有在粘滞键打开时才能向 5 键发送垃圾邮件(这将触发鼠标左键单击)。这将允许使用关闭粘滞键的快捷方式关闭脚本(按下该option键 5 次)。

到目前为止我的代码:

on idle
    tell application "System Preferences"
        activate
        set current pane to pane id "com.apple.preference.universalaccess"
    end tell

tell application "System Events"
    tell process "System Preferences"
        click menu item 6 of menu 1 --pseudocode
        if value of checkbox "Enable Mouse Keys" is 1 then
            key code 87 --press the "5" key, triggers mouse press
        end if
    end tell

    end tell

    set rn to (random number from 0.8 to 1.0) as text
    return rn
end idle

我的问题是线路click menu item 6 of menu 1以及如​​何访问“辅助功能”窗格的“鼠标和键盘”部分。如果还不是很明显,我对applescript的经验很少。>_>

在此处输入图像描述

4

2 回答 2

1

您可以避免打开 prefpane。通过直接从 Universal Access 首选项文件中读取值

set plistFile to (path to preferences from user domain) & "com.apple.universalaccess.plist" as string -- Get the  Universal Access plist path of this use
tell application "System Events" to set mouseDriver to value of property list item "mouseDriver" of contents of property list file plistFile -- read only the value for mouse keys

这将返回truefalse取决于它是否打开。

直接读取 plist 的一个警告是,在用户界面中所做的任何更改可能需要大约 5 秒或多或少的时间才能写入文件。

您可以在此处阅读有关属性列表项的更多信息

于 2013-03-09T14:48:06.660 回答
0

更新到上面针对 OS 10.14 Mojave 的@markhunte 帖子(可能也适用于早期版本):

set plistFile to (path to preferences from user domain) & "com.apple.universalaccess.plist" as string -- Get the  Universal Access plist path of this use
tell application "System Events" to set mouseDriver to value of property list item "stickyKey" of contents of property list file plistFile -- read only the value for mouse keys

plist 项目名称“mouseDriver”更改为“SickyKey”

于 2019-04-16T18:35:19.717 回答