2017-12-02 443 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