Last active
July 28, 2023 17:16
-
-
Save AndrianBdn/69484820345740156a78059d0219ee0f to your computer and use it in GitHub Desktop.
Typing command-line args inside VM or Remote Desktops on Mac
This file contains hidden or 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
#!/usr/bin/python | |
from __future__ import print_function | |
from time import sleep | |
import sys | |
import tempfile | |
import subprocess | |
import getpass | |
if len(sys.argv) < 2: | |
print("Using interactive mode for passwords...") | |
keyarg = getpass.getpass() | |
else: | |
keyarg = sys.argv[1] | |
for i in reversed(range(1, 6)): | |
sys.stdout.write("%d..." % (i)) | |
sys.stdout.flush() | |
sleep(1) | |
f = tempfile.NamedTemporaryFile() | |
for i in range(len(keyarg)): | |
code = "tell application \"System Events\"\n" | |
code += " keystroke \"%s\"\n" % (keyarg[i]) | |
code += "end tell\n" | |
f.seek(0) | |
f.truncate() | |
f.write(code); | |
f.flush() | |
subprocess.call(["/usr/bin/osascript", f.name]) | |
sleep(0.05) | |
print() | |
print("typed \"%s\"" % (keyarg)) | |
f.close(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment