Last active
March 6, 2023 13:35
-
-
Save nilninull/f366f6feeeb0b73dbaeff59f681cb1d2 to your computer and use it in GitHub Desktop.
A mpv script for turn off dpms while playing video automatically
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
-- save this file to $XDG_CONFIG_HOME/mpv/scripts/ | |
local dpms_mod = nil | |
-- local function dpms_mod_start(event) | |
-- print("RUN dpms mod start", dpms_mod) | |
-- if dpms_mod == nil then | |
-- -- This code was checked on xset 1.2.3 | |
-- if os.execute("[ `xset q | sed -n '/^DPMS/,${/^ DPMS/s/^ DPMS is //p}'` == Enabled ]") == 0 then | |
-- dpms_mod = true | |
-- else | |
-- dpms_mod = false | |
-- end | |
-- end | |
-- end | |
-- mp.register_event("video-reconfig", dpms_mod_start) | |
local function on_property_change(name, value) | |
print('RUN on property change', value, dpms_mod) | |
if dpms_mod == nil and value then | |
-- This code was checked on xset 1.2.3 | |
if os.execute("[ `xset q | sed -n '/^DPMS/,${/^ DPMS/s/^ DPMS is //p}'` == Enabled ]") == 0 then | |
dpms_mod = true | |
else | |
dpms_mod = false | |
end | |
end | |
end | |
mp.observe_property("vo-configured", "bool", on_property_change) | |
local function dpms_mod_stop(event) | |
if dpms_mod then | |
os.execute("xset +dpms") | |
end | |
end | |
mp.register_event("shutdown", dpms_mod_stop) | |
local function dpms_on_play(event) | |
if dpms_mod then | |
os.execute("xset -dpms") | |
end | |
end | |
mp.register_event("playback-restart", dpms_on_play) | |
local function dpms_on_pause(name, value) | |
if dpms_mod then | |
if value then | |
os.execute("xset +dpms") | |
else | |
os.execute("xset -dpms") | |
end | |
end | |
end | |
mp.observe_property("pause", "bool", dpms_on_pause) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't checking the return value of
grep(1)
also work? For example