指令碼自動控制顯示器開關

2021-09-25 10:23:34 字數 915 閱讀 9388

查了一下資料,可以用xset命令來實現對x的管理。而且xset在很多版本的linux系統中都可以使用,不僅有ubuntu, 還包括redhat, centos, debian, fedora以及macos。

xset開啟顯示器:

$ xset dpms force off

xset關閉顯示器:

$ xset dpms force on

關閉顯示器之後,如果鍵盤滑鼠有輸入,顯示器也會自動開啟。

接著寫乙個簡單的指令碼monitor_control.sh :

#!/bin/bash

export display=:0.0

if [ $# -eq 0 ]; then

echo usage: $(basename $0) "on|off"

exit 1

fiif [ $1 = "off" ]; then

xset dpms force off

elif [ $1 = "on" ]; then

xset dpms force on

else

echo usage: $(basename $0) "on|off"

fi然後修改一下monitor_control.sh的許可權:

$ chmod 744 monitor_control.sh

最後來寫crontab:每週一到周五,早上9點開啟顯示器,晚上6點關閉顯示器:

$ crontab -e

crontab

# 分 小時 月的第幾日 月份 周的第幾天 命令

0 9 * * 1-5 /path/to/monitor_control.sh on

0 18 * * 1-5 /path/to/monitor_control.sh off

好了,收工!找老闆領獎金去!

此頁面被訪問了 0 次

C 實現重啟 關機 開關顯示器的方法

using system using system.runtime.interopservices public static void reboot 重啟 public static void poweroff 關機 public static void logoff 登出 public stat...

Ubuntu 使用虛擬顯示器且遠端控制

已經使用的,備份 section monitor identifier monitor0 horizsync 28.0 80.0 vertrefresh 48.0 75.0 1920x1080 60.00 hz gtf hsync 67.08 khz pclk 172.80 mhz modeline...

Stm32的TFT LCD顯示器控制學習筆記

學習stm32,tft lcd顯示屏控制是很重要的一章,本人在初步學習stm32遇到了很多困難,所以把學習中積累的部分感覺重要的知識點羅列出來。目前常用的tft液晶內部驅動晶元是ili9320,ili9325系列,內部原理基本一致,我用的是ili9320。用stm32驅動液晶,實際上就是驅動ili9...