-
Notifications
You must be signed in to change notification settings - Fork 28
/
Get-Keychain-Access-Passwords.applescript
44 lines (40 loc) · 1.44 KB
/
Get-Keychain-Access-Passwords.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
-- @description
-- Handler to return keychain access items
-- Feel free to reuse this with whatever passwords you'd like
--
on getKeychain(keychainItemName)
do shell script "security 2>&1 >/dev/null find-generic-password -gl " & quoted form of keychainItemName & " | awk '{print $2}'"
if result is not "SecKeychainSearchCopyNext:" then
return (text 2 thru -2 of result)
else
display alert ("No " & keychainItemName & " keychain found!") ¬
message ("Press OK to set up a " & keychainItemName & " keychain, this is a one time step.") as critical ¬
buttons {"Cancel", "OK"} ¬
default button ("OK") ¬
cancel button "Cancel"
tell application "Keychain Access" to activate
delay 2
tell application "System Events"
tell process "Keychain Access"
set accountName to short user name of (system info)
keystroke "n" using {command down}
delay 1.5
set the clipboard to keychainItemName
keystroke "v" using {command down}
delay 1
keystroke tab
delay 1
set the clipboard to accountName
keystroke "v" using {command down}
delay 1
keystroke tab
display alert ("Almost Done") ¬
message ("Type in your " & keychainItemName & " password into the password field and click Add. Once it's saved run the script again.") as critical ¬
buttons {"Cancel", "OK"} ¬
default button ("OK") ¬
cancel button "Cancel"
end tell
end tell
return missing value
end if
end getKeychain