-
Notifications
You must be signed in to change notification settings - Fork 0
/
safari-passwords.txt
79 lines (68 loc) · 2.86 KB
/
safari-passwords.txt
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
on extract_host(website_description)
set AppleScript's text item delimiters to space
set word_list to every text item of website_description
repeat with w in reverse of word_list
if w contains "." then
return w
end if
end repeat
return last item of word_list
end extract_host
on quoted_field(field)
set saved_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "\""
set field_components to text items of field
set AppleScript's text item delimiters to "\"\""
set field to (field_components as string)
set AppleScript's text item delimiters to saved_delimiters
return "\"" & field & "\""
end quoted_field
set target_path to choose file name with prompt "Save passwords as:" default name "Safari Passwords.csv" default location (path to desktop)
tell application "Safari" to activate
tell application "System Events"
tell process "Safari"
set frontmost to true
set safari_menu to menu "Safari" of menu bar item "Safari" of first menu bar
set preferences_menu_item to first menu item of safari_menu whose value of attribute "AXIdentifier" is "Preferences"
click preferences_menu_item
click button 4 of toolbar of first window -- "Passwords" button does not provide an AXIdentifier attribute
-- wait for user to unlock password list
set waiting to true
repeat while waiting
try
set password_table to first table of first scroll area of first group of first group of first window
set waiting to false
end try
end repeat
-- clear search field
set search_field to first text field of first group of first group of first window
set value of search_field to ""
-- get all passwords
set row_count to count rows of password_table
set processed_rows to 0
set my progress total steps to row_count
set my progress completed steps to processed_rows
set my progress description to "Exporting passwords..."
set all to "url,username,password" & return
repeat with password_row in rows of password_table
set selected of password_row to true
set website to (description of static text of UI element 1 of password_row) as text
set website to my extract_host(website)
set username to name of UI element 2 of password_row
if username is not "—" then
set pass to name of UI element 3 of password_row
set all to all & my quoted_field(website) & "," & my quoted_field(username) & "," & my quoted_field(pass) & return
end if
set processed_rows to processed_rows + 1
set my progress completed steps to processed_rows
end repeat
end tell
end tell
set target_file to open for access target_path with write permission
write all to target_file as «class utf8»
close access target_file
set progress total steps to 0
set progress completed steps to 0
set progress description to ""
display notification (processed_rows as string) & " elements exported." with title "Export done"
delay 2