Skip to content

Instantly share code, notes, and snippets.

@alimbada
Last active April 22, 2024 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alimbada/389de49288afe70242c9aeffcd4b796d to your computer and use it in GitHub Desktop.
Save alimbada/389de49288afe70242c9aeffcd4b796d to your computer and use it in GitHub Desktop.
Hammerspoon script to set up hotkeys for controlling LG webOS TV input and on/off state
local lgtv_path = "~/opt/lgtv/bin/lgtv" -- Full path to lgtv executable
local tv_name = "MyTV" -- Name of your TV, set when you run `lgtv auth`
local lgtv_cmd = lgtv_path.." --name "..tv_name
local my_input = "HDMI_3"
local other_input = "HDMI_4"
function get_command(command)
command = lgtv_cmd.. " " ..command.. " --ssl"
return command
end
function exec_command(command)
command = get_command(command)
print("Executing command: " .. command)
response = hs.execute(command)
print(response)
return response
end
hs.hotkey.bind({"cmd", "shift", "ctrl"}, "1", function()
exec_command("on")
exec_command("setInput "..my_input)
end)
hs.hotkey.bind({"cmd", "shift", "ctrl"}, "2", function()
exec_command("on")
exec_command("setInput "..other_input)
end)
hs.hotkey.bind({"cmd", "shift", "ctrl"}, "=", function()
exec_command("on")
end)
hs.hotkey.bind({"cmd", "shift", "ctrl"}, "-", function()
exec_command("off")
end)
@alimbada
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment