2010-08-20 32 views
0

我想如果選擇另一個單選按鈕,在系統偏好設置點擊一個單選按鈕,如下所示:AppleScript的UI腳本 - 有條件

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 

if radio button "Right" is selected <-- pseudo-code 
    tell window "Mouse" 
     tell radio group 1 
      click radio button "Left" 
     end tell 
    end tell 
end if 

if radio button "Left" is selected <-- pseudo-code 
    tell window "Mouse" 
     tell radio group 1 
      click radio button "Right" 
     end tell 
    end tell 
end if 

end tell 
end tell 

人知道如何做到這一點?

回答

1

下面的腳本將恢復主鍵「左」如果當前設置爲「右」:

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

tell application "System Events" 
    tell process "System Preferences" 
     tell radio group "Primary mouse button:" of window "Mouse" 
      if value of radio button "Right" is 1 then 
       click radio button "Left" 
      end if 
     end tell 
    end tell 
end tell 

設置主鍵「右」會混淆了地獄,大多數用戶的。

+0

謝謝你的幫助! 只需插入一個else語句即可使其工作。 你是對的,大多數用戶會擔心,如果他們的主鍵被設置爲「正確」 - 但是由於肩傷,我在使用我的軌跡球時經常換手。 – timkl 2010-08-20 10:59:50