【问题标题】:Setting the mouse tracking speed via applescript通过applescript设置鼠标跟踪速度
【发布时间】:2010-12-13 10:32:40
【问题描述】:

我正在尝试获取一个苹果脚本来设置 OS X 10.6 中的鼠标跟踪速度,特别是使用新的 Magic Mouse。

我发现了以下内容:

将 trackingValue 设置为 5 --打开并激活系统偏好设置 告诉应用程序“系统偏好设置”激活 --尝试使用系统事件更改设置 告诉应用程序“系统事件” 告诉进程“系统偏好设置” 尝试 --打开“键盘和鼠标”面板 单击菜单栏1的菜单“视图”的菜单项“鼠标” 延迟 2 将滑块 1 的值设置为 trackingValue --结束告诉 错误 theError - 发生错误 显示对话框(“抱歉,更改键盘和鼠标设置时发生错误:”&返回和错误)按钮“确定”默认按钮“确定” 结束尝试 结束告诉 结束告诉

但它似乎是为 10.5 构建的,因为我在尝试“将滑块 1 的值设置为 trackingValue”时出错

2 个问题...

  1. 如何让它与 10.6/Magic Mouse 组合一起使用?
  2. 我将如何获取 slider on the control panel 的名称或任何其他控件的名称,以便在 applescript 中使用?

【问题讨论】:

    标签: osx-snow-leopard applescript


    【解决方案1】:

    这里有两件事情 - 首先,你需要检查了 “Enable access for assistive devices” 在System Preferences / Universal Access / Mouse & Trackpad。很显然,你已经做到了这一点,否则脚本不会得到的地方,它已经没有失败,但它是任何人都试图得到这个工作的一个重要步骤。 P>

    其次,你在接收到错误的行的问题是,你没有告诉的AppleScript在哪里可以找到你想改变的值的滑块。通过改变线的下面,该脚本开始工作:

    set value of slider "Tracking Speed" of window "Mouse" to trackingValue
    

    注意,以及命名窗口由我的AppleScript可以使用也称为滑块被使用。虽然运行Snow Leopard和使用“滑动件1”,在窗口“滚动速度”第二滑块正在改变。因此,通过使用滑块,而不是其数量的名称,我们忽略任何可能的索引问题。至于工作了滑块的名字吗?我简单地使用,随着它去的标签,在这种情况下工作的价值尝试。大小可能不同,当然。 P>

    因此,最终的脚本变为:

    set trackingValue to 5
    
    --Open and activate System Preferences
    tell application "System Preferences" to activate
    
    --Attempt to change settings using System Events
    tell application "System Events"
        tell process "System Preferences"
            try
                --Open the "Keyboard & Mouse" pane
                click menu item "Mouse" of menu "View" of menu bar 1
                delay 2
                set value of slider "Tracking Speed" of window "Mouse" to trackingValue
                --end tell
            on error theError
                --An error occured
                display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
            end try
        end tell
    end tell
    

    【讨论】:

    • 我不得不做出对变化...滑块的设定值窗口的“跟踪”,“鼠标”,以trackingValue ......但除此之外,你的脚本的伎俩。谢谢
    • 脚本工作对我来说没有任何修改。干得漂亮,并很好地解释! SPAN>
    • 它也为我工作时我使用:滑块的设定值窗口的“跟踪”,“鼠标”到trackingValue。 ?一个很好的例子.. :)感谢名单一个问题 - 你能告诉我们类似的脚本来设置:鼠标右键弹出按钮的动作来辅助按钮动作 SPAN>
    【解决方案2】:

    如果您使用的是 Mavericks 10.9,则需要考虑一个额外的选项卡组,此脚本有效:

    set trackingValue to 8
    
    --Open and activate System Preferences
    tell application "System Preferences" to activate
    
    --Attempt to change settings using System Events
    tell application "System Events"
        tell process "System Preferences"
            try
                --Open the "Keyboard & Mouse" pane
                click menu item "Mouse" of menu "View" of menu bar 1
                delay 2
    
                tell tab group 1 of window "Mouse"
                    set value of slider "Tracking" to trackingValue
                end tell
                --end tell
            on error theError
                --An error occured
                display dialog ("Sorry, an error occured while altering Keyboard and Mouse settings:" & return & theError) buttons "OK" default button "OK"
            end try
        end tell
    end tell
    

    【讨论】:

      【解决方案3】:

      Jason 的建议在 10.8 中似乎不起作用。我试图用“Tracking”替换“Tracking Speed”,该值没有相应地设置。

      不知道他们是否更改了滑块的名称。

      【讨论】:

        【解决方案4】:

        脚本在 OS X Lion 10.7 中仍能正常运行。我在设置跟踪速度值后添加的一个小改动是:

                set value of slider "Tracking Speed" of window "Mouse" to trackingValue
                tell application "System Preferences" to quit
                --end tell
        

        这会关闭“系统偏好设置”,这样我就不会一直盯着菜单窗格,并且可以使用鼠标现在更快的跟踪来回到我的工作中。

        【讨论】:

          【解决方案5】:

          这适用于我的 Sierra OS X 机器。如果您遇到错误,您可能需要稍微延长一个或两个脚本延迟,以更好地匹配您的机器速度。

          set trackingValue to 8
          
          --Open and activate System Preferences
          tell application "System Preferences" to activate
          
          --Attempt to change settings using System Events
          tell application "System Events"
              tell process "System Preferences"
                  try
                      delay 1
                      --Open the "Mouse" pane
                      click menu item "Mouse" of menu "View" of menu bar 1
                      delay 0.5
                      tell window "Mouse"
                          set value of slider "Tracking speed" to trackingValue
                      end tell
                  on error theError
                      --An error occured
                      display dialog ("Sorry, an error occured while altering Mouse settings:" & return & theError) buttons "OK" default button "OK"
                  end try
              end tell
          end tell
          
          tell application "System Preferences" to quit
          

          【讨论】:

            【解决方案6】:

            由于某些原因,这些脚本无法在 OS X 10.10 中运行。需要稍作调整,但现在可以了。

            set trackingValue to 9
            
            --Open and activate System Preferences
            tell application "System Preferences" to activate
            tell application "System Preferences"
                reveal pane "com.apple.preference.mouse"
            end tell
            --Attempt to change settings using System Events
            tell application "System Events"
                tell process "System Preferences"
                    tell tab group 1 of window "Mouse"
                        set value of slider "Tracking" to trackingValue
                    end tell
                end tell
            end tell
            tell application "System Preferences" to quit
            

            享受吧。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2011-12-09
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2017-02-24
              • 1970-01-01
              相关资源
              最近更新 更多