I have a do shell script
that I need to run in Applescript, but it needs to run as a different user. It is to be deployed into the student's network drive as a standalone application that the students can run when required.
The example code below is only for illustration.
This code works when I am logged in, because it's picking up my username (local admin account) on the computer and uses the password provided (not the actual password included).
do shell script "rm -rf /$HOME/Downloads/*" password "Password01" with administrator privileges
I have tried to specify a username with user "sdadmin"
to the code and it won't work, it throws an error.
Is there a way to ask AppleScript to run a command with a specific user and password provided in the code like above?
Best Answer
Updated answer:
There is an Apple doc which shows the correct way of doing it. You was close.
(I have not tried it myself)
do shell script "rm -rf /$HOME/Downloads/*" user name "USERNAME" password "THEPASSWORD" with administrator privileges
From the doc:
IMPORTANT UPDATE 2
*You can save the app as "run only" (Save an editable copy for yourself first)
( If you only save it as a Run Only even you will not be able to open it and edit it later on once you have closed the script window.)
Then use the File->Export menu which will give you the option in the save dialogue to save as "Run Only"
Attempt to open main.scpt file in application package:
A Run only will stop someone from opening the script embedded in the Application by double clicking on it to open it in Script Editor and discover your password. But there is a way of finding the user name and password from a Run Only and it is not that hard to figure out even for a casual user.
I WOULD THINK TWICE ABOUT PUTTING YOUR USER NAME AND PASSWORD IN THE APP.
UPDATE 3
A little idea to help if you must do this is to break up the password text by creating nonsensical variable name to hold it and jumble them.
When the code runs it will reassemble them in the correct order.
For example.
if the password is 88>0TpFpax
I will use:
Notice that not only do the variable not mean anything or show any sense of order but the bits of password are also jumbled within them.
All until the code runs.
So even if they do stumble on how to do what I am talking about the password will not be assembled in any order that it can just be used.