Skip to content

Instantly share code, notes, and snippets.

@mpepping
Created April 6, 2019 12:20
Show Gist options
  • Save mpepping/af304a276fdc9148efb90a4510cceccb to your computer and use it in GitHub Desktop.
Save mpepping/af304a276fdc9148efb90a4510cceccb to your computer and use it in GitHub Desktop.
AppleScript to copy a Safenet MobilePASS OTP
-- 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
@lcb
Copy link

lcb commented Dec 1, 2020

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.

@mpepping
Copy link
Author

mpepping commented Dec 13, 2020

@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

@cloudmustafa
Copy link

cloudmustafa commented Dec 13, 2020

Thank you!! It works!!!!!

@mpepping
Copy link
Author

@cloudmustafa posted a small update to the script of my previous comment. Maybe it useful ..

@jmccartan
Copy link

Outstanding! Thanks for sharing!!

@marfrede
Copy link

marfrede commented Feb 9, 2024

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