Skip to content

Instantly share code, notes, and snippets.

@kepocnhh
Created October 15, 2023 12:47
Show Gist options
  • Save kepocnhh/00ebe6aa8d73ac48cce1c2d6c0d315b5 to your computer and use it in GitHub Desktop.
Save kepocnhh/00ebe6aa8d73ac48cce1c2d6c0d315b5 to your computer and use it in GitHub Desktop.
OS X security add generic password
#!/usr/local/bin/bash
echo 'Enter service name (default is common):'
read SERVICE_NAME || exit 1
if test -z "$SERVICE_NAME"; then
SERVICE_NAME='common'; fi
echo 'Enter account name:'
read ACCOUNT_NAME || exit 1
if test -z "$ACCOUNT_NAME"; then
echo 'Account name is empty!'; exit 1; fi
echo 'Enter password:'
read -rs PASSWORD_VALUE || exit 1
if test -z "$PASSWORD_VALUE"; then
echo 'Password is empty!'; exit 1; fi
APPLICATION='' # todo
security add-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" -w "$PASSWORD_VALUE" -T "$APPLICATION"
if test $? -ne 0; then
echo "Add password to $SERVICE_NAME/$ACCOUNT_NAME error!"; exit 1; fi
echo "Add passord to $SERVICE_NAME/$ACCOUNT_NAME success."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment