Last active
April 22, 2024 11:13
-
-
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
This file contains 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires https://github.com/klattimer/LGWebOSRemote