-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcopy-password.applescript
executable file
·46 lines (34 loc) · 1.46 KB
/
copy-password.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
44
45
46
#!/usr/bin/osascript
on run argv
# Open passwords window
do shell script "open /Library/Apple/System/Library/CoreServices/SafariSupport.bundle/Contents/PreferencePanes/Passwords.prefPane"
set searchQuery to (item 1 of argv)
tell application "System Events"
tell window "Passwords" of process "System Preferences"
# Wait for search field to be available
repeat until ((first text field whose subrole is "AXSearchField") exists)
delay 0.1
end repeat
# Enter the search query
set value of first text field whose subrole is "AXSearchField" to searchQuery
set results to outline 1 of scroll area 1
if not (row 2 of results exists) then
display notification "No entry found for " & searchQuery & "."
tell me to quit
end if
# First result is the second row, first row is the search field
set firstResult to row 2 of results
# Select the first result
set selected of firstResult to true
# Copy the password
set passwordField to first button of scroll area 1 of group 1 whose description is "Password"
perform action "AXShowMenu" of passwordField
click menu item 1 of menu 1 of passwordField
# Show a success notification
set domainName to value of static text 1 of UI element 1 of firstResult
set accountName to value of static text 2 of UI element 1 of firstResult
display notification accountName with title "Password copied" subtitle domainName
end tell
tell application "System Preferences" to quit
end tell
end run