1 """Script to install/uninstall HA into OS X."""
10 """Set up to run via launchd on OS X."""
11 with os.popen(
"which hass")
as inp:
12 hass_path = inp.read().strip()
14 with os.popen(
"whoami")
as inp:
15 user = inp.read().strip()
17 template_path = os.path.join(os.path.dirname(__file__),
"launchd.plist")
19 with open(template_path, encoding=
"utf-8")
as tinp:
22 plist = plist.replace(
"$HASS_PATH$", hass_path)
23 plist = plist.replace(
"$USER$", user)
25 path = os.path.expanduser(
"~/Library/LaunchAgents/org.homeassistant.plist")
28 with open(path,
"w", encoding=
"utf-8")
as outp:
30 except OSError
as err:
31 print(f
"Unable to write to {path}", err)
34 os.popen(f
"launchctl load -w -F {path}")
36 print(
"Home Assistant has been installed. Open it here: http://localhost:8123")
40 """Unload from launchd on OS X."""
41 path = os.path.expanduser(
"~/Library/LaunchAgents/org.homeassistant.plist")
42 os.popen(f
"launchctl unload {path}")
44 print(
"Home Assistant has been uninstalled.")
47 def run(args: list[str]) -> int:
48 """Handle OSX commandline script."""
49 commands =
"install",
"uninstall",
"restart"
50 if not args
or args[0]
not in commands:
51 print(
"Invalid command. Available commands:",
", ".join(commands))
54 if args[0] ==
"install":
57 if args[0] ==
"uninstall":
60 if args[0] ==
"restart":
67 raise ValueError(f
"Invalid command {args[0]}")
None open(self, **Any kwargs)