summaryrefslogtreecommitdiffstats
path: root/ui-macos/askpass.py
blob: 55e98ee0c3a14153ff045bf667a0b58338698aa4 (plain)
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
#!/usr/bin/env python
import sys, os, re, subprocess

prompt = ' '.join(sys.argv[1:2]).replace('"', "'")

if 'yes/no' in prompt:
    print "yes"
    sys.exit(0)

script="""
	tell application "Finder"
		activate
		display dialog "%s" \
			with title "Sshuttle SSH Connection" \
			default answer "" \
			with icon caution \
			with hidden answer
	end tell
""" % prompt

p = subprocess.Popen(['osascript', '-e', script], stdout=subprocess.PIPE)
out = p.stdout.read()
rv = p.wait()
if rv:
    # if they press the cancel button, it returns nonzero
    sys.exit(1)
g = re.match("text returned:(.*), button returned:.*", out)
if not g:
    sys.exit(2)
print g.group(1)