用于为鼠标首选项设置主按钮、辅助按钮和其他属性的 Apple 脚本 [英] Apple Script to set Primary Button, Secondary Button and other properties for Mouse Preference

查看:26
本文介绍了用于为鼠标首选项设置主按钮、辅助按钮和其他属性的 Apple 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能推荐我:

如何设置主按钮、辅助按钮按钮和鼠标的其他属性通过 AppleScript 偏好?

How to set Primary Button, Secondary Button and other properties of Mouse Preference via AppleScript?

我现在已经试过了,脚本:

I have now tried this, script:

tell application "System Preferences"
    activate
end tell
tell application "System Events"
    tell process "System Preferences"
        click menu item "Mouse" of menu "View" of menu bar 1
        tell window "Mouse"
            set value of pop up button 1 to "Primary Button"
        end tell
    end tell
end tell

但它给出了这个错误信息:

but it is giving this error message:

系统事件出错:无法获取弹出窗口鼠标"的按钮 1处理系统偏好设置".无效的索引.

System Events got an error: Can't get pop up button 1 of window "Mouse" of process "System Preferences". Invalid index.

谁能告诉我哪里可能出错或有什么更好的技巧来实现它?

Can anyone suggest me where I may be wrong or some better trick to implement it?

谢谢,

米拉吉

推荐答案

这是我的版本,它消除了上面 Christopher Kemp 的帖子中显示的键盘技巧"的需要.此外,它还有一些额外的东西,比如运行检查以确保辅助设备设置为打开",以及一个对话框,以便您可以选择将鼠标设置为左手还是右手.希望它有帮助:)

Here's my version which eliminates the need for the "keyboard tricks" as shown in the post from Christopher Kemp above. Plus it has a few extra things thrown in like running a check to make sure assistive devices is set to 'on', and a dialog box so you can select whether you want the mouse to be set as left or right handed. Hope it helps :)

附言这是针对 10.6 (Snow Leopard) 的……您必须稍微更改它以适应 10.5 (Leopard) 首选项窗格的差异.

P.S. This is for 10.6 (Snow Leopard)...you'd have to change it slightly to suit the 10.5 (Leopard) preference pane differences.

--

# check 'Enable access for assistive devices' is ON

tell application "System Events"

if UI elements enabled then

    # open dialog
    set question to display dialog "Select your mouse preference." buttons {"Left Handed", "Right Handed", "Cancel"} default button 3 with title "Mouse Switch"

    set answer to button returned of question

    if answer is equal to "Left Handed" then

        # open Mouse preferences & set left button to Secondary
        tell application "System Preferences"

            activate
            reveal pane "Mouse"

        end tell

        tell application "System Events"

            tell process "System Preferences"

                # set Secondary Button
                click pop up button 4 of group 1 of window "Mouse"
                click menu item "Secondary Button" of menu of pop up button 4 of group 1 of window "Mouse"
                # set Primary Button
                click pop up button 5 of group 1 of window "Mouse"
                click menu item "Primary Button" of menu of pop up button 5 of group 1 of window "Mouse"

            end tell

        end tell

        tell application "System Preferences" to quit

        display dialog "Your mouse is now set to: Left Handed" buttons {"OK"}

    end if

    if answer is equal to "Right Handed" then

        # open Mouse preferences & set right button to Secondary
        tell application "System Preferences"

            activate
            reveal pane "Mouse"

        end tell

        tell application "System Events"

            tell process "System Preferences"

                # set Secondary Button
                click pop up button 5 of group 1 of window "Mouse"
                click menu item "Secondary Button" of menu of pop up button 5 of group 1 of window "Mouse"
                # set Primary Button
                click pop up button 4 of group 1 of window "Mouse"
                click menu item "Primary Button" of menu of pop up button 4 of group 1 of window "Mouse"

            end tell

        end tell

        tell application "System Preferences" to quit

        display dialog "Your mouse is now set to: Right Handed" buttons {"OK"}

    end if

    # if 'Enable access for assistive devices' is OFF show error
else

    display dialog "Please select 'Enable access for assistive devices' from the Universal Access preference pane to run this script." buttons {"OK"} default button 1 with icon caution

end if

end tell

这篇关于用于为鼠标首选项设置主按钮、辅助按钮和其他属性的 Apple 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆