Posted on 09-17-2019 11:27 AM
Hi all,
I'm trying to get applescript to open terminal as the logged in user, ask for credentials for sudo, switch to the working directory and then run a shell script. I've been working on it for 3 days and still no closer to getting it working. I have tried countless websites for advice but nothing seems to be getting this to work.
This is the script below;
User=$( who | grep console | cut -d" " -f 1 )
sudo -u ${User} /usr/bin/osascript <<EOF
tell application "Terminal"
activate
do script "sudo echo Running bootstrap. Please wait..."
"cd /tmp/12345/macOS/" in window 1
"sh ./12345_bootstrap.sh" in window 1
end tell
EOF
exit 0
Posted on 09-17-2019 11:38 AM
Can you explain why you feel you need to do it this way? For example, why does the script need to be run as the user and ask for credentials? If you can give us some details on what the script is doing, I'm willing to bet you can do this straight from Self Service or another type of policy trigger without needing to go through trying to get it to run a local script.
Posted on 09-18-2019 11:56 PM
Jamf policy runs as sudo already.
In you script you "cd" to a temp location and then call to run a script (local to the Mac), why not run the script as part of the policy, instead of downloading it as mm2270 mentioned?
A context/explanation of the policy and that "12345_bootstrap.sh" script may be helpful to understand what you need to accomplish.
How is that script delivered? Is it a package from the same policy?