Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
74 lines (69 sloc) 2.97 KB
# 1Password One Time Password Retriever and Connect to Viscosity Connection
# Written by Jared Williams <thisis@jared.nyc>
#
# Variable Description:
# opName is the case sensitive name of the 1Password entry containing
# your OTP auth key for the vpn.
# vpnName is the case sensitive name of the connection in Viscosity.
# commandString sets the name of the 1Password helper agent, i wasnt
# sure if the string in front of .com.agilebits was different
# for everyone so i made it dynamic.
# trimOTP removes the special characters pulled from 1Password with the OTP.
#
# If you have any questions or comments, heres the ways to reach me:
# email: thisis@jared.nyc
# slack: https://devopschat.co signing up is free and my username is @jaredwilliams
# github: @jaredmichaelwilliams
# reddit: jaredw
#
# Installation:
# 1. Copy this file into apple's Script Editor
# 2. Go to Menu Bar -> File -> Export
# 3. Name it something easy, and change the dropdown box to application so that it
# doesnt open the Script editor everytime
# 4. Open System Preferences
# 5. Go to the Security & Privacy tab
# 6. Go down to Accessibility
# 7. Click the add button ('+')
# 8. Select the newly exported application.
# 9. Youre done! Happy automating!
#
#
display dialog "Enter your 1Password Password" default answer "" with hidden answer
set PP to text returned of result
set commandString to "ps aux | grep -Eo '([A-Z0-9]{10})(.com.agilebits.onepassword4-helper)'"
set OPHP to do shell script commandString
###### Change these Values ######
set opName to "One Password Entry containing OTP key"
set vpnName to "Viscosity Connection Name"
###### End Value Change ######
tell application "System Events"
tell application process OPHP
tell menu bar item 1 of menu bar 1 to click
try
set value of text field "Master Password" of window 1 to PP
tell button "Unlock" of window 1 to click
end try
repeat until text field 1 of window 1 exists
end repeat
delay 1
set value of text field 1 of window 1 to opName
repeat until row 2 of table 1 of scroll area 1 of window 1 exists
end repeat
tell row 2 of table 1 of scroll area 1 of window 1
key code 124
end tell
repeat until UI element 1 of row 8 of table "Details" of scroll area 1 of pop over 1 of UI element opName of UI element opName of row 2 of table 1 of scroll area 1 of window 1 exists
end repeat
set OTP to name of every static text of UI element 1 of row 8 of table "Details" of scroll area 1 of pop over 1 of UI element opName of UI element opName of row 2 of table 1 of scroll area 1 of window 1
set OneTime to second item of OTP
set trimOTP to (do shell script "echo " & quoted form of OneTime & " | tr -d '•'")
end tell
tell application process "Viscosity"
tell application "Viscosity" to connect vpnName
repeat until window 1 exists
end repeat
set value of text field 1 of window 1 to trimOTP
tell button 1 of window 1 to click
end tell
end tell