-
Notifications
You must be signed in to change notification settings - Fork 0
/
safaripass.scpt
58 lines (49 loc) · 1.69 KB
/
safaripass.scpt
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
tell application "Safari"
set theURL to URL of front document
end tell
property shellPath : "/opt/local/bin:/usr/local/bin:$PATH"
set theURL to getDomain(theURL)
set nTitle to "pass"
set nPrompt to "Which password do you want?"
set entity to the text returned of (display dialog nPrompt default answer theURL with title nTitle)
set pw to do shell script "export PATH=" & shellPath & "; pass " & entity
set thePW to ""
set theUsername to ""
repeat with pwline in (paragraphs of pw)
if thePW = "" then
set thePW to pwline
else if (theUsername = "") then
repeat with prefix in {"username", "login"}
if (pwline starts with prefix) then
set theUsername to findAndReplaceInText(pwline, (prefix & ": "), "") as string
end if
end repeat
end if
end repeat
if (theUsername = "") or (thePW = "") then
display dialog "Login/Password not found"
end if
tell application "Safari"
activate
tell application "System Events"
keystroke theUsername
keystroke tab
delay 1
keystroke thePW
end tell
end tell
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
on getDomain(theURL)
set theURL to findAndReplaceInText(theURL, "http://", "")
set theURL to findAndReplaceInText(theURL, "https://", "")
set SuffixOffset to offset of ("/") in theURL
set theURL to (characters 1 thru (SuffixOffset - 1) of theURL) as string
set theURL to findAndReplaceInText(theURL, "www.", "")
end getDomain