苹果脚本来设置主要按钮,辅键和其他属性鼠标preference [英] Apple Script to set Primary Button, Secondary Button and other properties for Mouse Preference
问题描述
任何人都可以给我建议:
Can anyone suggest me:
如何设置主要按钮,中学
按键和鼠标的其他属性
通过AppleScript的preference?
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鼠
流程系统preferences。无效
指数。
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?
谢谢,
Miraaj
推荐答案
下面是我的版本,它省去了在从上面克里斯托弗·坎普后显示的键盘招数的需要。加上它有扔在像运行检查,以确保辅助设备一些额外的东西被设置为开,并出现一个对话框,以便您可以选择是否要为左或右手鼠标设置。希望它可以帮助:)
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 :)
P.S。这是10.6(雪豹)...你必须改变它稍微适应10.5(Leopard)的preference窗格中的差异。
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
这篇关于苹果脚本来设置主要按钮,辅键和其他属性鼠标preference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!