2009-11-05 48 views
3

我想要獲得一個蘋果腳本來設置OS X 10.6中的鼠標跟蹤速度,特別是使用新的Magic Mouse。通過applescript設置鼠標跟蹤速度

我發現以下幾點:

 
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 1 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 

但似乎爲10.5待建,因爲我想

兩個問題「滑塊1至trackingValue設定值」時得到一個錯誤。 ..

  1. 我怎樣才能得到這個10.6 /魔術鼠標組合?
  2. 我怎麼會去得到slider on the control panel的名稱,或任何其它控制就此而言,在AppleScript的使用?

回答

3

這裏有兩件事 - 首先,您需要檢查System Preferences/Universal Access/Mouse & Trackpad中的「Enable access for assistive devices」。很明顯,你已經完成了這個任務,否則腳本就不會失敗,但是對於其他任何試圖實現這個目標的人來說,這是一個重要的步驟。

其次,你在收到錯誤的行,問題是,你不說的AppleScript在哪裏可以找到你想要改變的值滑塊。通過改變線以下,腳本開始工作:即以及命名窗口由AppleScript的使用

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

注意,我也入選了可使用滑塊。在運行Snow Leopard並使用「滑塊1」時,窗口「滾動速度」中的第二個滑塊正在改變。因此,通過使用滑塊的名稱而不是其數量,我們可以繞過任何可能的索引問題。至於解出滑塊的名字?我只是嘗試使用與它一起使用的標籤的值,這在該實例中起作用。當然,你的里程可能會有所不同。

因此,最終的腳本變爲:

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 
+1

我不得不做出對變化......窗口「鼠標」,以trackingValue 的滑蓋「跟蹤」的 設定值......但除此之外,你的腳本的伎倆。謝謝 – Jason 2009-11-08 14:35:28

+0

腳本沒有任何修改就爲我工作。很好地完成並很好地解釋! – mikeh 2009-12-10 18:28:33

+0

它也適用於我當我使用:設置窗口「鼠標」的滑塊「跟蹤」的值TrackingValue。一個很好的例子.. Thanx :)一個問題 - 你能告訴我們類似的腳本來設置:右鍵彈出按鈕的動作到輔助按鈕的動作? – Devarshi 2010-08-19 14:16:41

0

腳本仍然用作用於與OS X獅子10.7。我設置跟蹤速度值之後增加了一個小的變化是:

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

這會關閉系統偏好設置,所以我沒有離開看着菜單窗格,可以回到我與我的鼠標現在更快的跟蹤工作。

0

傑森的建議似乎不工作在10.8。我試圖用「跟蹤」替換「跟蹤速度」,該值並未對應設置。

不知道他們是否更改了滑塊的名稱。

1

如果您使用的小牛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 
-1

出於某種原因,這些腳本沒有在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 

享受。

0

這適用於我的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