`security unlock-keychain` from a bash script - bash

On MacOSX, if I ssh in and run the command:
security -v unlock-keychain -p <password> <keychain_path>
The keychain unlocks and all is well with the world.
If I put that same command into a bash script and run
bash test.sh
I get prompted for the password.
How can I get around this?

You need to explicitly let your script test.sh access your keychain.
Open the Keychain Access
Right click on the private key
Select "Get Info"
Select "Access Control" tab
Click "Allow all applications to access this item"
Click "Save Changes"
Enter your password
Enjoy
Credits: Running xcodebuild from a forked terminal

Related

Cannot get keychain password via SSH

On a Mac (Big Sur) machine, I can easily get a password from the keychain via the command line:
security find-generic-password -l Foo -w
But, if I ssh into that same machine, the exact same command returns nothing.
Any ideas why that would be happening?
Jeff Holt's response helped me.
Indeed the remote keychain was locked and can be unlocked with security unlock-keychain. If you are interacting via the command line perhaps using a script you can test for whether the default keychain is unlocked with show-keychain-info which returns a non-zero value when locked.
In bash selectively prompt to unlock the keychain (with squashing of the redundant text output of show-keychain-info to stderr):
if ! $(security show-keychain-info 2> /dev/null); then
security unlock-keychain;
fi

How do you set the icon for a MacOS app, when you aren't building with Xcode?

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

The ctrl button on my mac isn't working

Is there an alternative way to shutdown servers when i'm using terminal?
or do I have to get it fixed. I'm a student
If you have sudo rights then add following alias to your .bashrc
alias poweroff='sudo /sbin/shutdown -h now'
Then you only need to type poweroff in your terminal and type in the administrator password
just change in the machine menu
Input/keyboard/Keyboard settings/
and in the tab
Input/Virtual Machine/
The "Host Key Combination" to Ctrl+Alt instead of Right Ctrl. That will solve it.

osascript and sudo password entry

I am using osascript in a BASH script for dialog boxes on a MAC system. The problem I am having is several of the commands I need to use require privilages to function correct. If I use sudo in the BASH script, the password prompt shows in the terminal window. Is the some way I can hook the sudo password prompt into an osascript dialog box? Or is there a different way I can handle asking for the password in an osascript dialog box and passing it to some other program to handle it?
What worked for me was to create the BASH script and then use osascript to call it.
$ osascript -e 'do shell script "/Path/yourbashscript.sh" with administrator privileges'
This will prompt a dialog box straight from Apple's infrastructure. Same one you see when you're asked for your username & password.
You can run this in terminal or use a third-party wrapper like, Platypus
You can suppress the password interface by modifying your Mac's authorization rights.
Use the built-in security command line tool or authbuddy to change the system.preferences.accessibility right to allow:
sudo security authorizationdb write system.preferences.accessibility allow
Opening up the system.preferences.accessibility right will permit any user to change the accessibility settings without a password prompt.

Running AppleScript in Terminal

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

Resources