2011-10-25 43 views
1

使用AppleScript我想在多臺機器上自動創建新的用戶帳戶。我正在嘗試使用UI腳本,並且似乎無法在「iChat帳戶首選項」窗口的「添加帳戶」(+)按鈕上執行單擊命令。我試圖使用Accessibility Inspector.app來推斷按鈕的名稱,但我仍然無法通過AppleScript訪問它。使用AppleScript在偏好窗口中單擊加號(+)按鈕

根據輔助Inspector.app按鈕具有以下屬性:

AXRole: AXButton 
AXRoleDescription: button 
AXHelp: <nil> 
AXEnabled: YES 
AXFocused (W): NO 
AXParent: <AXGroup> 
AXWindow: <AXWindow:AXStandardWindow> 
AXTopLevelUIElement: <AXWindow:AXStandardWindow> 
AXPosition: x=225.00 y=462.00 
AXSize: w=23.00 h=22.00 
AXTitle: <empty string> 
AXIdentifier: _NS:27 
AXDescription: Add Account 

下面是一個簡單起動的AppleScript,將讓你的帳戶首選項窗口:

tell application "iChat" 
    activate 
    tell application "System Events" 
     tell process "iChat" 
      tell menu bar 1 
       click menu item "Preferences…" of menu "iChat" 
      end tell 
      click button "Accounts" of tool bar 1 of window 1 
      click button "Add Account" of window "Accounts" 
     end tell 
    end tell 
end tell 

請注意,第9行是我想要工作。下面你會找到一個指向iChat帳戶首選項窗口截圖的鏈接,其中一個箭頭指向我試圖訪問的按鈕。另請注意,我知道我只需使用「擊鍵選項卡」即可進入(+)按鈕,但這並不總是奏效,因爲您必須按選項卡更改的次數取決於您已創建的帳戶類型我聊天。

iChat Account Preferences Window

回答

2

並不是每一個UI對象都有一個標題,所以在這種情況下,你可以只使用項目編號 - 請注意,你需要包括在Inspector窗口中顯示的整個層次。

tell application "iChat" 
    activate 
    tell application "System Events" 
     tell process "iChat" 
      tell menu bar 1 to click menu item "Preferences…" of menu "iChat" 
      delay 0.5 
      tell window 1 
       click button "Accounts" of tool bar 1 
       delay 0.5 
       click button 1 of group 1 of group 1 
      end tell 
     end tell 
    end tell 
end tell 
+0

這沒有把戲。謝謝! – psyrendust

相關問題