4

I have a Mac and I'm programming a sort of security script (I know it's useless and overkill but I'm just trying to expand my knowledge of Python) and one of the steps in my script requires a password from the admin before it can execute.

I want to make it so this script will execute under certain circumstances and I don't want it to require any human interaction. I've tried doing the following:

os.system("sudo -s")            
os.system("my password")

However, it tells me that I typed the password wrong (clearly Apple made it so you can't have a program type it).

In short, I've tried everything. I then figured out that you can copy and paste the password and it works. So my question is: how can I have my script copy and paste the password and then hit enter? Alternatively, is there a better way to achieve this?

1

1 Answer 1

3

I think you need to have a capital "-S", so it should look like:

p = os.system('echo {}|sudo -S {}'.format('my password', 'command to run'))

By the way, the reason for you not to do this is less about how you can mess up your computer using sudo and more about how you are going to have a script on your computer with your sudo password stored in plain text.

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

1 Comment

Michael is there any way to ask for password with system dialog by script and get the result in the script?

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.