1#!/usr/bin/env python3
2import os
3from pathlib import Path
4import subprocess
5import sys
6
7
8helper = str(Path(__file__).resolve().with_name("mac-agent-vm.py"))
9if sys.argv[1:] == ["--clipboard"]:
10 with subprocess.Popen(["/usr/bin/pbpaste"], env={**os.environ, "LC_CTYPE": "en_US.UTF-8"}, stdout=subprocess.PIPE) as clipboard:
11 try:
12 result = subprocess.run(
13 [sys.executable, helper, "exec", "/usr/bin/env", "LC_CTYPE=en_US.UTF-8", "/usr/bin/pbcopy"],
14 stdin=clipboard.stdout,
15 )
16 finally:
17 clipboard.stdout.close()
18 if clipboard.wait() or result.returncode:
19 sys.exit(1)
20 print("VM clipboard updated. Press Command-V in the VM.")
21else:
22 os.execv(sys.executable, [sys.executable, helper, "ssh", *sys.argv[1:]])