![我正在寻找一个闪屏命令(如果可能的话,使用彩色)](https://linux22.com/image/906796/%E6%88%91%E6%AD%A3%E5%9C%A8%E5%AF%BB%E6%89%BE%E4%B8%80%E4%B8%AA%E9%97%AA%E5%B1%8F%E5%91%BD%E4%BB%A4%EF%BC%88%E5%A6%82%E6%9E%9C%E5%8F%AF%E8%83%BD%E7%9A%84%E8%AF%9D%EF%BC%8C%E4%BD%BF%E7%94%A8%E5%BD%A9%E8%89%B2%EF%BC%89.png)
我正在使用 xfce4 计时器,我希望闹钟除了弹出警报外还能使屏幕闪烁。目前我正在使用
xset dpms force off; sleep 3; xset dpms force on
它可以让屏幕再次熄灭,但我希望它能够以彩色闪烁,并且如果可能的话,以闪烁的方式更快地闪烁
问候
答案1
我编写了一个 bash 脚本来达到该目的:
flash-primary-screen.sh
bash 脚本
将此 bash 脚本复制到你的计算机:
#!/bin/bash
# NAME: flash-primary-screen.sh
# PATH: ~/bin
# DESC: Flashes primary screen colours to alert timer has ended.
# DATE: November 15, 2018
# NOTE: Written for: https://askubuntu.com/a/1092835/307523
# I'm looking for a command to flash screens (if possible in colors)
# Change 6 variables below to control screen flashing levels
MaxBright="1.5"
MinBright=".5"
MaxRed="2.0"
MaxGreen="2.0"
MaxBlue="2.0"
MinGamma=".5"
declare aXrandr=()
# Next two functions lifted from: eyesome internet sunrise/sunset time screen
# brightness and gamma controller: https://github.com/WinEunuuchs2Unix/eyesome
InitXrandrArray () {
# Array is used for each monitor and searched by name.
# Save time to search on connected/disconnected, primary monitor,
# brightness level, gamma level.
mapfile -t aXrandr < <(xrandr --verbose --current)
} # InitXrandrArray
SearchXrandrArray () {
# Parms: $MonXrandrName = xrandr monitor name to search for.
# NOTE: Entries in array follow predicatble order from xrandr --verbose:
# <MONITOR-NAME> connected / disconnected (line 1 of monitor entry)
# Gamma: 0.99:0.99:0.99 (line 5 of entry)
# Brightness: 0.99 (line 6 of entry)
# CRTC: 9 (line 8 of entry)
fNameFnd=false
fBrightnessFnd=false
fGammaFnd=false
fCrtcFnd=false
XrandrConnection=disconnected
XrandrPrimary=false
XrandrGamma=""
XrandrBrightness=""
XrandrCRTC="" # Laptop lid open value=0, lid closed=blank
for (( i=0; i<"${#aXrandr[*]}"; i++ )) ; do
line="${aXrandr[$i]}"
# Have we looped to next monitor and not found search string?
if [[ "$line" =~ " connected " ]] && [[ $fNameFnd == true ]] ; then
break
fi
if [[ "$line" =~ ^"$MonXrandrName connected" ]]; then
fNameFnd=true
XrandrConnection=connected
[[ "$line" =~ "primary" ]] && XrandrPrimary=true
fi
if [[ $fNameFnd == true ]] && [[ $fGammaFnd == false ]] ; then
if [[ "$line" =~ "Gamma: " ]]; then
fGammaFnd=true
XrandrGamma="${line##* }"
# TODO: Use `xgamma` for accuracy
fi
fi
if [[ $fGammaFnd == true ]] && [[ $fBrightnessFnd == false ]] ; then
if [[ "$line" =~ "Brightness: " ]]; then
fBrightnessFnd=true
XrandrBrightness="${line##* }"
fi
fi
if [[ $fBrightnessFnd == true ]] && [[ $fCrtcFnd == false ]] ; then
if [[ "$line" =~ "CRTC: " ]]; then
fCrtcFnd=true
XrandrCRTC="${line##* }"
break
fi
fi
done
} # SearchXrandrArray
FlipBright () {
if [[ $NewBrightness == "$MaxBright" ]] ; then
NewBrightness="$MinBright"
else
NewBrightness="$MaxBright"
fi
} # FlipBright
CleanUp() {
xrandr --output "$MonXrandrName" --gamma "$SaveGamma" \
--brightness "$SaveBrightness"
# Compensate for bug in Xrandr as of Nov 15, 2018 with second call
InitXrandrArray
SearchXrandrArray
xrandr --output "$MonXrandrName" --gamma "$XrandrGamma"
exit 0
} # CleanUp
Main () {
trap CleanUp INT TERM
# Get primary monitor current settings
XrandrName=$(xrandr --current | grep primary)
MonXrandrName="${XrandrName%% *}"
InitXrandrArray
SearchXrandrArray
# Did we find primary monitor ok?
if [[ $fBrightnessFnd == false ]] || [[ $fGammaFnd == false ]] ; then
echo "Internal Error: Could not find Primary Screen brightness or gamma"
echo XrandrPrimary: "$XrandrPrimary"
echo aXrandr[0]: "${aXrandr[0]}"
echo Brightness: "$XrandrBrightness"
echo Gamma: "$XrandrGamma"
exit 2
fi
# Restore these values when CleanUping program
SaveBrightness="$XrandrBrightness"
SaveGamma="$XrandrGamma"
# Wait for <Ctrl>+C or until parent kills us.
while true ; do
if [[ $Red == true ]] ; then
Red=false
Green=true
NewGamma="$MaxRed:$MinGamma:$MinGamma"
FlipBright
elif [[ $Green == true ]] ; then
Green=false
NewGamma="$MinGamma:$MaxGreen:$MinGamma"
FlipBright
else
Red=true
NewGamma="$MinGamma:$MinGamma:$MaxBlue"
FlipBright
fi
xrandr --output "$MonXrandrName" --gamma "$NewGamma" \
--brightness "$NewBrightness"
sleep .2
done
} # Main
Main "$@"
使用以下方法将脚本标记为可执行:
chmod a+x /path/flash-primary-screen.sh
/path
您将脚本放在哪里的目录。
从程序(甚至是命令行)调用脚本。要结束脚本,请按Ctrl+ C。
改变定义的前 6 个变量来操纵亮度级别和颜色级别的变化。
请随时在下面的评论部分提出问题或发表建议!
您还可以在终端中显示彩色闪烁的 ASCII 艺术文本:
脚本如下:
#!/bin/bash
From: http://wiki.bash-hackers.org/scripting/terminalcodes
DATA[0]=" _/ _/ _/ _/ "
DATA[1]=" _/_/_/_/_/ _/_/_/ _/_/_/ _/_/_/ _/_/_/ "
DATA[2]=" _/ _/ _/ _/ _/ _/ _/_/ _/ _/"
DATA[3]="_/_/_/_/_/ _/ _/ _/ _/ _/_/ _/ _/ "
DATA[4]=" _/ _/ _/_/_/ _/_/_/ _/_/_/ _/ _/ "
# virtual coordinate system is X*Y ${#DATA} * 5
REAL_OFFSET_X=0
REAL_OFFSET_Y=0
draw_char() {
V_COORD_X=$1
V_COORD_Y=$2
tput cup $((REAL_OFFSET_Y + V_COORD_Y)) $((REAL_OFFSET_X + V_COORD_X))
printf %c ${DATA[V_COORD_Y]:V_COORD_X:1}
}
trap 'exit 1' INT TERM
trap 'tput setaf 9; tput cvvis; clear' EXIT
tput civis
clear
while :; do
for ((c=1; c <= 7; c++)); do
tput setaf $c
for ((x=0; x<${#DATA[0]}; x++)); do
for ((y=0; y<=4; y++)); do
draw_char $x $y
done
done
done
done
要生成 ASCII 艺术,您可以使用 Figlet 或 Toilet。请参阅:当终端打开时我可以显示当前日历和时间吗?