Skip to content

Instantly share code, notes, and snippets.

@stravos97
Last active May 31, 2024 23:43
Show Gist options
  • Save stravos97/0c7d78d88e5da33a782e2832f660deb1 to your computer and use it in GitHub Desktop.
Save stravos97/0c7d78d88e5da33a782e2832f660deb1 to your computer and use it in GitHub Desktop.
import Apple Keychain Passwords CSV into pass (password store)
Use the script below with a CSV to import Apple Keychain Passwords into the Unix Password Store (pass). The script imports entries with the fields Title, URL, Username, and Password. Other field headers should be removed from the CSV. Customize the CHANGE-ME placeholders to match your specific setup. The script checks for correct arguments and file existence, sets the base directory to CHANGE-ME, reads the CSV line by line, handles missing passwords, and creates entries in the specified directory within pass. You can modify the script to import additional fields as currently only Title, URL, Username, and Password will be imported.
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 path_to_csv_file"
exit 1
fi
CSV_FILE=$1
# Check if the CSV file exists
if [ ! -f "$CSV_FILE" ]; then
echo "CSV file not found!"
exit 1
fi
# Define the base directory for the entries
# Change this to point to your password store directory you want to .gpg keys to go in
BASE_DIR="CHANGE-ME"
# Read the CSV file line by line
# Add more fields here if your csv has any more
tail -n +2 "$CSV_FILE" | while IFS=, read -r Title URL Username Password; do
# Handle potential NaN values in the Password column
if [ -z "$Password" ]; then
echo "Skipping entry for $Title due to missing password."
continue
fi
# Define the entry path and content
ENTRY_PATH="$BASE_DIR/$Title"
CONTENT="$Password
url: $URL
user: $Username"
# Create the entry in the pass store
echo "$CONTENT" | pass insert --multiline "$ENTRY_PATH"
done
echo "Password entries have been imported successfully into the CHANGE-ME directory."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment