Skip to content
Permalink
Browse files
Merge pull request #3 from apache/macOSandArgs
Add macOS pbcopy and allow args for generic app
  • Loading branch information
gstein committed Dec 11, 2019
2 parents c11d459 + 796d013 commit 7b27d077c163b06f4e9071f583b10db86c1c73b4
Showing 1 changed file with 18 additions and 9 deletions.
27 otp.py
@@ -13,6 +13,7 @@
import argparse
import hashlib
import subprocess
import platform

OTP_PWD_FILE = '.otp'
PASSWORD_LEN = 20
@@ -132,15 +133,18 @@ def main():
parser = argparse.ArgumentParser(description='Compute OTP strings.')
parser.add_argument('--test', help='Run the test suite.', nargs=0,
action=RunTests)
parser.add_argument('args', nargs=argparse.REMAINDER)

# Note: this may exit, if tests are run.
_ = parser.parse_args()

line = input('Challenge? ')
parts = line.split()
if len(parts) < 3:
print('ERROR: challenge must have: ALGO SEQUENCE SEED')
sys.exit(1)
parsed = parser.parse_args()

parts = parsed.args
if len(parts) < 3: # we don't have enough args, prompt
line = input('Challenge? ')
parts = line.split()
if len(parts) < 3: # still not enough
print('ERROR: challenge must have: ALGO SEQUENCE SEED ...')
sys.exit(1)

algo = parts[0]
seq = int(parts[1])
@@ -162,9 +166,14 @@ def main():
value = processor(seed + pwd, seq)
response = ' '.join(to_words(value))
print('Response:', response)


osname = platform.system()

# Attempt to push this to the clipboard
result = subprocess.run(['xclip', '-selection', 'clipboard'], input=response.encode())
if osname == 'Darwin':
result = subprocess.run(['pbcopy', '-pboard', 'general'], input=response.encode())
else:
result = subprocess.run(['xclip', '-selection', 'clipboard'], input=response.encode())
if result.returncode == 0:
print('NOTE: copied to clipboard')

0 comments on commit 7b27d07

Please sign in to comment.