I am running a script in AppleScript in which I use tell application "Terminal" to do a specific script that needs sudo privileges in Terminal. When prompted, the user running the script must enter the sudo password in Terminal to allow the script to bind the laptop to active directory.
What command can I use to get the script to stop running if the sudo password entered in Terminal is incorrect? Right now if the user enters the password incorrectly, the script will keep running the rest of the commands except it ultimately fails in the end because it is unable to bind to AD without the credentials to do so.
May I ask why you're running this code specifically in the Terminal.app? When using a do shell script you can run the do shell script with administrator privileges (equivalent to sudo) and without using Terminal.app.
do shell script "disconfigad -f -a " & computerName & " -domain .local -u " & user_name & "-p" & user_password & " -ou 'CN=Computers,DC=,DC=local'" user name "<administrator>" password "<password>" with administrator privilege
Related
I have created a Mac OS app. I am building the app on Ubuntu, and not able to make use of Xcode. When it comes to setting an icon for the app, I am at a loss. How can this be done?
This might appear as a duplicate to this question:
How do I set the icon for my application's Mac OS X app bundle?
However, the solution given here (to simply add the CFBundleIconFile tag in info.plist, with the associated .icns file in the app's Resources directory) does not work for me, nor does it appear to work for some others in that thread. The answer is quite old - is there a newer process? Or, must other steps be taken to get this to work? I am using a program called Image2icon to generate an .icns file - is it that this is not sufficient, and a different process must be taken to generate the .icns?
Good evening, first question with answer, is that once the icon created and placed in the resource your current has not changed? (imagine that in the file info.plist you have named the icon) in this case you may have to delete 2 files to find the new icons below I leave you an applescriipt script that delete them 2 files that the system recreates automatically. in the script you have to change "yourname" and "yourpassword" by your username and password otherwise it will not work. once launched the script the screen will go black and reappear, I put xtrafinder, if you do not use it, erase the line with xtrafinder.
try
set erase to do shell script "sudo find /private -name" & quoted form
of "com.apple.dock.iconcache" user name "yourname" password
"yourpassword" with administrator privileges
do shell script "echo" & quoted form of erase do shell script "sudo rm
-rf -v" & quoted form of erase user name "yourname" password "yourpassword" with administrator privileges
set erase to do shell script "echo" & quoted form of erase & " | sed 's
com.apple.dock.iconcache#com.apple.iconservices#'"
set erase to do shell script "echo" & quoted form of erase
do shell script "sudo rm -rf -v" & quoted form of erase user name
"yourname" password "yourpassword" with administrator privileges
do shell script "sudo killall Dock" user name "yourname" password
"yourpassword" with administrator privileges
do shell script "sudo killall iconservicesagent" user name "yourname"
password "yourpassword" with administrator privileges
do shell script "Sudo killall Finder" user name "yourname" password
"yourpassword" with administrator privileges quit application
"XtraFinder"
do shell script "Sudo open -a /Applications/XtraFinder.app" user name
"yourname" password "yourpassword" with administrator privileges
do shell script "sudo pkill loginwindow" user name "yourname" password
"yourpassword" with administrator privileges
end try
I am attempting to create a script that will grab the serial number of the Mac and set it to the HostName, LocalHostName, & ComputerName with out it prompting for administrator credentials. So far this is what I have and trying to work through it.
How do I put the credentials in the script to where it pulls the info without prompting?
set sys to do shell script "/usr/sbin/system_profiler SPHardwareDataType " without altering line endings
set StringVariable1 to "Serial"
set Serial_Number to do shell script "/usr/sbin/system_profiler SPHardwareDataType | awk '/Serial/ { print $NF }' "
do shell script "scutil --set HostName " & Serial_Number with administrator privileges
do shell script "scutil --set LocalHostName " & Serial_Number with administrator privileges
do shell script "scutil --set ComputerName " & Serial_Number with administrator privileges
display dialog "The Mac has been renamed to " & Serial_Number
I am using a script to automatically set up a computer. I need to assign a password to the vnc server for the user, which is normally done using the vncserver command. However, it prompts for the user to enter and re-enter their password, neither of which the script is capable of doing.
So, how can I set up the VNC password without an interactive prompt?
Please try following bash script sample:
#!/bin/sh
vncpasswd << EOF
123456
123456
EOF
I am using below command to open putty through windows command prompt:
PUTTY.EXE -ssh -pw "mypass" user#IP -m C:/my.sh -t
Where my.sh mentioned in above command file contains:
sudo su - rootuser
After executing the command, putty console is opened and it prompts for password.
Is there any way where I can provide this password automatically without typing it?
There's a bit of a horrible workaround using Expect and embedding a password.
This is a bad idea.
As an alternative:
Configure sudo to allow NOPASSWD.
Login directly as root using public-private key auth.
Both these introduce a degree of vulnerability, so should be used with caution - but any passwordless auth has this flaw.
Finally, after struggling for almost whole day, I got the way to get this working.
Below command can be executed from windows machine:
PLINK.EXE -t -ssh -pw "password" user#IP /home/mydir/master.sh
master.sh file is located on remote machine. And this file contains below command to execute script with sudo command without prompting password.
echo password | sudo u user -S script.sh
Here, password should be replaced with your password. user should be replaced with your actual user and script.sh is the script on remote machine that you want to fire after sudo login.
I have a lua script, running on the Mac, that needs to call sudo.
I'd hoped that Mac OS would automatically bring up a password request dialog, but instead it the command fails by returning 256.
Is there anyway that I can achieve my goal?
Tim
Quick and easy way: run it like this
/usr/bin/osascript -e 'do shell script "/path/to/myscript args 2>&1 etc" with administrator privileges'
Proper and configurable way: use AuthorizationExecuteWithPrivileges API from Authorization Services (in Security.framework).
Both will display standard Mac OS X GUI asking for administrator password and then execute the command as root, the same way as sudo does except that SUDO_USER environment variables will not be set.
If you need to execute individual commands from under user account when you're already elevated to root, you can prepend them with /usr/bin/sudo -u $USER.