1

I've found sh-script for CPU Throttling and would like to schedule it on startup using AppleScript in the following way:

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

And get the following error:

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

P.S: The pass provided to the sh file is being fully copied from the Get Info option (CDM + I)

2
  • 1
    Do not use sudo together with with administrator privileges See TechNote 2065. Remove sudo Commented Dec 2, 2017 at 17:42
  • 1
    While varian makes and excellent point, nonetheless the primary reason it errors out is you're attempting to execute a script that is not set as executable, or executed as a direct argument to the execution of a shell. See my answer for details. Commented Dec 2, 2017 at 17:58

1 Answer 1

1

Not even sure how you received that error message when the do shell script command shown in your question does not even compile.

The "password mypassword" portion actually has to be password "mypassword" for it to compile.

The reason you're getting:

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

Is because cputhrottler.sh is not set as executable.

Make it executable using the following command:

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

This will allow it to execute and not throw that particular error message.

Or use the following convention:

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

Note that sudo was replaced with sh, or use other shell. In this manner the shell script does not need to be made executable.

Sign up to request clarification or add additional context in comments.

2 Comments

You were right it's not the executable state and using the convention makes it execute perfectly. Thank you very much :)
@Bohdan Afanasyev, Yes, to directly execute a shell script it has to be made executable, otherwise it has to be passed as an argument to the execution of a shell itself. Both methods will work, it's just a matter of preference. Personally I prefer to make my shell scripts directly executable vs passing as an argument to the execution of a shell.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.