Last active
May 13, 2024 19:34
-
-
Save cmer/bd40d9da0055d257c5aab2e0143ee17b to your computer and use it in GitHub Desktop.
Wake TV when MacOS wakes from sleep (Hammerspoon)
This file contains hidden or 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
-- ------------------------------------------------------------------- | |
-- 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ) :And then add this :
If you want other keys and not f1,2,3,4, just replace the strings with desired keys.