2012-04-13 240 views
8

AppleScript和系統事件有問題。AppleScript - 系統事件錯誤:禁用輔助設備訪問

我已在「系統偏好設置」的「通用訪問」首選項窗格中選中「啓用對輔助設備的訪問」。

當我嘗試:

arch -i386 osascript -e 'tell application "System Events" to get the position of every window of every process'

我有這樣的錯誤:

System Events got an error: Access for assistive devices is disabled. (-25211)

你有什麼想法?

非常感謝

回答

8

問題不在於輔助裝置。 AppleScript似乎錯誤地返回錯誤代碼,當它試圖訪問一個永遠不能有任何窗口的進程的窗口(在我的情況下,它是「谷歌瀏覽器助手」)。

您需要捕捉錯誤。這個工作對我來說:

tell application "System Events" 
    set procs to processes 
    set windowPositions to {} 
    repeat with proc in procs 
     try 
      if exists (window 1 of proc) then 
       repeat with w in windows of proc 
        copy w's position to the end of windowPositions 
       end repeat 
      end if 
     end try -- ignore errors 
    end repeat 
end tell 
return windowPositions 

返回座標對,如{{1067,22},{31,466},{27,56},{63,22},{987,22名單}} - 你試圖得到什麼?

+0

謝謝,我會努力this.Last的問題,我怎麼能確定窗口在船塢(隱藏),或在前面? – Tokytok 2012-04-13 13:38:37

9

在Mac OS X 10.9上,當AppleScript編輯器不允許使用輔助功能時,實際上會發生同樣的錯誤。

這裏是你如何啓用它:

轉到系統預置>安全&隱私>隱私>輔助

enter image description here

之後,只是檢查留給的AppleScript編輯器複選框和錯誤應該消失。

+7

如果通過'osascript'從命令行運行腳本,您還需要將Terminal添加到啓用輔助功能的應用程序中。 – devios1 2015-10-30 22:52:54

1

與此頁面上有關Mac OS X 10.9(Mavericks)的文章類似,要在Mac OS X 10.8上解決此問題(也可能在較早版本的OS X上),您需要確保「啓用訪問系統偏好設置「的」輔助功能「窗格中啓用了」輔助設備「選項。

enter image description here

相關問題