-
-
Save cmer/bd40d9da0055d257c5aab2e0143ee17b to your computer and use it in GitHub Desktop.
-- ------------------------------------------------------------------- | |
-- THIS SCRIPT IS NOW DEPRECATED IN FAVOR OF A MORE ROBUST SOLUTION -- | |
-- Please refer to https://github.com/cmer/lg-tv-control-macos/ | |
-- ------------------------------------------------------------------- | |
local tv_identifier = "LG TV" | |
local mac_address = "aa:bb:cc:dd:ee:ff" | |
local tv_found = (hs.screen.find(tv_identifier) ~= nil) | |
local debug = false -- Set to true to enable debug messages | |
if debug then | |
print("List of all screens: " .. hs.inspect(hs.screen.allScreens())) | |
if tv_found then print("TV with identifier '"..tv_identifier.."' was detected.") end | |
end | |
watcher = hs.caffeinate.watcher.new(function(eventType) | |
if (eventType == hs.caffeinate.watcher.screensDidWake or | |
eventType == hs.caffeinate.watcher.systemDidWake or | |
eventType == hs.caffeinate.watcher.screensDidUnlock) and tv_found then | |
if debug then print("TV was turned on.") end | |
hs.execute("/opt/homebrew/bin/wakeonlan "..mac_address) | |
end | |
end) | |
watcher:start() |
Hey are either of you hitting an issue where the LGTV Web OS Remote package doesn't stay installed on your machine? I keep having to reinstall it. Maybe it's a work thing.
It should definitely stay installed. Are the files just getting deleted?
Nice work on the repo. One option that I eventually want to add is a check to see if the current TV input is set to the mac's input before actually turning the TV off. This feature is on the windows LGTVCompanion app and avoids the TV turning off because your mac goes to sleep while you're on a different input.
I haven't had any issue with needing to reinstall anything. Could try changing the install method/location to see if that helps avoid whatever is removing it.
I'm taking it up with my IT department, yes the files get deleted and the library.
I also thought about checking the Input before switching, haven't had time to implement.
This is an amazing idea, @greyshi — I mostly use the TV as a monitor for my Mac, but can see how that’d be annoying.
I’ll try to see if I can whip this together. Or feel free to submit a PR!
Your wishes have been answered, @greyshi!
Wow that was quick! Going to give it a try.
LG's latest C2 update requires SSL enabled. LGWebOSRemote dev has updated the code to support ssl, but now the Lua code needs to reflect "lgtv path command ssl" to pass commands to the TV.
I tried appending ssl
to the commands in Lua and still not working for me... I will hopefully have time to play with it more later today.
Wondering if I could get some help. I have installed Hmmerspoon & brew. I am reviewing the instructions to install LGWebOS (https://github.com/klattimer/LGWebOSRemote) but it says I have to have several other things installed (Requires wakeonlan, websocket for python (python3-websocket for python3), and getmac. python-pip (python3-pip for python3) and git are required for the installation process.). Is this correct? I'm not sure how to install all of these things on my Mac
@jmart987 have you seen the latest repo here? https://github.com/cmer/lg-tv-control-macos
hope that helps!
@jmart987 have you seen the latest repo here? https://github.com/cmer/lg-tv-control-macos
hope that helps!
Appreciate that, I'm not sure if I had the latest repo. But how do I install lgtvcontrol from this?
Do I just put this in terminal after installing hammer spoon and brew?
mkdir -p ~/opt
python -m venv ~/opt/lgtv
cd ~/opt/lgtv
source bin/activate
pip install git+https://github.com/klattimer/LGWebOSRemote
When I do that nothing really happens. I get a zsh: command not found
@jmart987 try it one line at a time instead of copying and pasting the whole thing.
@jmart987 have you seen the latest repo here? https://github.com/cmer/lg-tv-control-macos
hope that helps!
Works great! If you want to change inputs by using keyboard events/taps you could also add this in the .lua
file ( I have this line at the top ) :
local control_inputs = true -- Switch inputs by events from keyboard
And then add this :
event = hs.eventtap.new({hs.eventtap.event.types.keyDown, hs.eventtap.event.types.systemDefined}, function(event)
local type = event:getType()
if type == hs.eventtap.event.types.keyDown then
local keyCode = hs.keycodes.map[event:getKeyCode()]
if keyCode == "f1" then
exec_command("setInput HDMI_1")
elseif keyCode == "f2" then
exec_command("setInput HDMI_2")
elseif keyCode == "f3" then
exec_command("setInput HDMI_3")
elseif keyCode == "f4" then
exec_command("setInput HDMI_4")
end
end
end)
if control_inputs then
event:start()
end
If you want other keys and not f1,2,3,4, just replace the strings with desired keys.
Nice stuff @cmer !