Created
April 6, 2019 12:20
-
-
Save mpepping/af304a276fdc9148efb90a4510cceccb to your computer and use it in GitHub Desktop.
AppleScript to copy a Safenet MobilePASS OTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- AppleScript to copy a Safenet MobilePASS OTP. | |
-- | |
-- 'osascript ~/path/to/token.applescript' | |
-- Set 'passwd' to your MobilePASS passcode. | |
set passwd to "0000" | |
-- Start MobilePASS | |
tell application "MobilePASS" | |
activate | |
delay 1 | |
end tell | |
-- Copy token | |
tell application "System Events" | |
tell table 1 of scroll area 1 of window "MobilePASS" of application process "MobilePASS" | |
delay 1 | |
select row 1 | |
end tell | |
keystroke passwd | |
delay 1 | |
set uiScript to click UI element "Copy Passcode" of window "MobilePASS" of application process "MobilePASS" | |
end tell | |
-- Quit MobilePASS | |
tell application "MobilePASS" | |
quit | |
end tell |
@cloudmustafa Good question. Have your tried increasing the delay on line 15 or 19?
I have a somewhat newer version of this script .. maybe that can make the difference for your system.
-- AppleScript to copy a SafeNet MobilePASS OTP.
set passwd to "0000"
-- Make sure MobilePASS is not running
tell application "MobilePASS"
quit
delay 0.5
end tell
-- Start MobilePASS
tell application "MobilePASS"
activate
delay 0.2
end tell
-- Copy token
tell application "System Events"
-- Give the window focus in a robust way
set frontmostProcess to first process where it is frontmost
set visible of frontmostProcess to false
repeat while (frontmostProcess is frontmost)
delay 0.1
end repeat
set secondFrontmost to name of first process where it is frontmost
set frontmost of frontmostProcess to true
-- Select the first item in the list
tell table 1 of scroll area 1 of window "MobilePASS" of application process "MobilePASS"
delay 0.5
select row 1
end tell
-- Fill the input field with the value from the passwd variable
keystroke passwd
delay 0.5
-- Copy the passcode
set uiScript to click UI element "Copy Passcode" of window "MobilePASS" of application process "MobilePASS"
end tell
-- Quit MobilePASS
tell application "MobilePASS"
quit
end tell
Thank you!! It works!!!!!
@cloudmustafa posted a small update to the script of my previous comment. Maybe it useful ..
Outstanding! Thanks for sharing!!
thanks @mpepping !
I improved this a little further for an even faster approach :-)
takes not even one second now.
(for example by using set value of text field to passwd
instead of keystroke passwd
)
-- AppleScript to copy a Safenet MobilePASS OTP.
--
-- 'osascript ~/path/to/token.applescript'
-- Set 'passwd' to your MobilePASS passcode.
set passwd to "0000"
-- Make sure MobilePASS is not running
tell application "MobilePASS"
quit
delay 0.2
end tell
-- Start MobilePASS
tell application "MobilePASS" to activate
-- Copy token
tell application "System Events"
tell window "MobilePASS" of application process "MobilePASS"
-- Select the first item in the list
tell table 1 of scroll area 1 to select row 1
-- Fill the input field with the value from the passwd variable
set value of text field 1 to "4321"
-- Copy the passcode
set uiScript to click UI element "Copy Passcode"
end tell
end tell
-- Quit MobilePASS
tell application "MobilePASS" to quit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very nice, thanks a lot!
Edit: BTW you can set delay to fractions (e.g. delay 0.1) to make it faster. For me 100 msec is usually enough.