2017-03-18 1621 views
2

我的代碼是在Mac應用程序運行的AppleScript時,「不允許輔助訪問」錯誤

NSAppleScript* scriptObject = [[NSAppleScript alloc] initWithSource: 
           @"\ 
           tell application \"System Preferences\"\n\ 
           set current pane to pane id \"com.apple.preference.energysaver\"\n\ 
           end tell\n\ 
           tell application \"System Events\"\n\ 
           tell process \"System Preferences\"\n\ 
           tell window 1\n\ 
           tell group 1 -- automatic graphics switching\n\ 
           tell checkbox 1 -- automatic graphics switching\n\ 
           click\n\ 
           end tell\n\ 
           end tell\n\ 
           end tell\n\ 
           end tell\n\ 
           end tell"]; 

returnDescriptor = [scriptObject executeAndReturnError: &errorDict]; 

它打算自動改變圖形,當我嘗試它,我有錯誤

System Events got an error:「mactest」is not allowed for assistive access

我確定代碼是正確的,它在AppleScript編輯器中運行良好,並且在刪除「click \ n \」行時也可以正常運行。 我已經將我的應用以及AppleScript編輯器添加到安全&隱私中,但仍然無用。

回答

0

我相信我也遇到過這個問題。我想製作一個小AppleScript來關注並最大化StepMania。我將它作爲應用程序導出,以便將它添加到登錄項目中。添加最大化功能後,我給了AppleScript編輯器的可訪問性權限。

System Preferences -> Security & Privacy -> Privacy -> Accessibility -> AppleScript Editor

但是,導出爲一個應用程序之後,它現在不通過的AppleScript編輯器運行,並且沒有所需的輔助功能的權限。

AppleScript app is not allowed assistive access

你需要給你的應用程序可訪問權限。

AppleScript app would like to control this computer using accessibility features

一些像這樣的對話可能會導致你拖動您的應用程序列表。

相關問題