2017-12-02 149 views
1

我發現SH-腳本CPU節流,並想以下列方式使用AppleScript來安排它在啓動時:做shell腳本導致找不到命令

do shell script "sudo /Users/BohdanAir/Documents/Automation/cputhrottler.sh" "password mypassword" with administrator privileges 

並得到以下錯誤:

error "sudo: /Users/BohdanAir/Documents/Automation/cputhrottler.sh: command not found" number 1 

PS:提供給sh文件該過程被完全從Get Info選項複製(CDM + I)

+1

**不要用'使用'sudo'連同管理員privileges' **見[技術說明2065](https://developer.apple.com/library/content/technotes/tn2065/_index.html)。刪除'sudo' – vadian

+1

雖然瓦里安製造和良好的出發點,但是主要的原因是出現了錯誤是你試圖執行未設置爲可執行,或作爲直接的shell的參數執行執行的腳本。詳情請參閱我的回答。 – user3439894

回答

1

甚至不知道你怎麼收到錯誤消息,當你的問題甚至不編譯所示的do shell script命令

"password mypassword"部分實際上必須是password "mypassword"爲它來編譯。

你得到的理由是:

error "sudo: /Users/BohdanAir/Documents/Automation/cputhrottler.sh: command not found" number 1 

是因爲cputhrottler.sh未設置爲可執行文件。

使其可執行使用以下命令

chmod u+x /Users/BohdanAir/Documents/Automation/cputhrottler.sh 

這將允許它來執行,而不是拋出一個特定的錯誤消息。

或者使用以下約定:

do shell script "sh /Users/BohdanAir/Documents/Automation/cputhrottler.sh" password "mypassword" with administrator privileges 

注意sudosh更換,或使用其他。通過這種方式,shell腳本不需要被執行製作。

+0

你是對的,它不是可執行狀態,使用約定使它完美執行。非常感謝你:) – volna

+0

@Bohdan阿法納西耶夫,是的,直接執行它必須做出可執行的shell腳本,否則它作爲參數傳遞給一個殼本身的執行傳遞。兩種方法都行得通,這只是一個偏好問題。我個人更喜歡使我的shell腳本直接可執行,並將其作爲參數傳遞給shell的執行。 – user3439894