Skip to content

Instantly share code, notes, and snippets.

@Gabelbombe
Last active October 9, 2022 17:02
Show Gist options
  • Save Gabelbombe/9c518f405315dc3087c3 to your computer and use it in GitHub Desktop.
Save Gabelbombe/9c518f405315dc3087c3 to your computer and use it in GitHub Desktop.
AppleScript to automate Keychain acceptance
function Accepts ()
{
osascript <<EOF
tell application "System Events"
repeat while exists (processes where name is "SecurityAgent")
tell process "SecurityAgent" to click button "Allow" of window 1
delay 0.2
end repeat
end tell
EOF
}
function AcceptWithCreds ()
{
username="$1"
password="$2"
[ -z "${password}" ] && return 1
osascript 2>/dev/null <<EOF
set appName to "${username}"
set appPass to "${password}"
tell application "System Events"
repeat while exists (processes where name is "SecurityAgent")
tell process "SecurityAgent"
if exists (text field 1 of window 1) then
set value of text field 1 of window 1 to appName
set value of text field 2 of window 1 to appPass
end if
end tell
tell process "SecurityAgent" to click button "Allow" of window 1
delay 0.2
end repeat
end tell
EOF
echo 'Finished...'
}
#!/bin/bash
# Run above script in another window
sudo security dump-keychain -d login.keychain > ~/Desktop/Keychains/keychain-login.txt
sudo security dump-keychain -d /Library/Keychains/System.keychain > ~/Desktop/Keychains/keychain-system.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment