BASH可以在系统托盘中显示为应用程序指示器吗?
我有一个bash脚本,在一段时间后锁定屏幕 ( 应用程序将在Ubuntu设定的时间后锁定屏幕 )。 我想在Ubuntu的系统托盘/应用程序指示器栏中显示剩余时间。
我发现的最好的方法是本文的系统监视器指示器 : webupd8.org – 显示bash的Ubuntu应用程序指示器 。 它在Unity系统托盘/应用程序指示条上显示bash脚本“echos”的文本。
上面的文章针对的是带有Unity的Ubuntu 16.04。 有关Xubuntu,Gnome-Shell + app-indicator扩展和Budgie的更多信息,请访问开发人员网站: fossfreedom / indicator-sysmonitor 。 另请访问该站点以获取更详细的安装和配置说明。
安装和配置indicator-sysmonitor
要安装系统监视器指示器,您需要首先指定PPA,其中可以找到indicator-sysmonitor
:
sudo add-apt-repository ppa:fossfreedom/indicator-sysmonitor sudo apt-get update sudo apt-get install indicator-sysmonitor
现在从Dash( Alt + F2 )运行“indicator-sysmonitor”GUI。
- 单击显示为“cpu:99%mem:99%”的系统托盘区域
- 选择“首选项”
- “常规”选项卡最初处于活动状态,单击“启动时运行”框
- 选择“高级”选项卡
- 单击“ 新建”按钮以添加新控件
- 在Sensor字段中输入
custom
- 在描述字段中键入
Bash Indicator
_在命令字段中键入bash脚本的名称,即/mnt/e/bin/indicator-sysmonitor-display
- 保存新的自定义指标
- 突出显示
custom
行,然后单击“ 添加”按钮将其激活。 - 您可以删除“CPU”和“Mem”的默认变量,这些变量可能对您没有帮助。
- 我将刷新时间间隔从
2
秒更改为.3
秒。 支持下面解释的“旋转披萨”。 - 现在单击“ 保存”按钮。
Sysmonitor指标在行动
这个.gif
显示了Ubuntu的Unity系统托盘更新时的外观。
- 在动画开始时,我们的系统输出包含“亮度:3000”。
- 然后启动
multi-timer
(下面的链接)并逐步执行多个计时器。 - 出现旋转披萨以及剩余时间倒计时。
注意:系统监视器指示器还显示“亮度:3000”。 这是我的英特尔背光硬件亮度级别的白天设置(链接如下)。
Sysmonitor指标BASH脚本
创建类似于以下内容的脚本,并将其分配给Sysmonitor指标中的变量{Custom}
:
#!/bin/bash # UPDT: May 30 2018 - Cohesion with new multi-timer and old lock-screen-timer. if [ -f ~/.lock-screen-timer-remaining ]; then text-spinner Spinner=$(cat ~/.last-text-spinner) # read last text spinner used String=$(cat ~/.lock-screen-timer-remaining) systray="$Spinner $String" else systray="" fi if [ -f /tmp/display-current-brightness ]; then Brightness=$(cat /tmp/display-current-brightness) systray="$systray Brightness: $Brightness" else systray="$systray Brightness: OFF" fi # Below for AU answer: https://askubuntu.com/questions/1024866/is-it-possible-to-show-ip-address-on-top-bar-near-the-time # default_interface=$(route -n | awk '$1 == "0.0.0.0" {print $8; exit}') # ip_address=$(ifconfig "$default_interface" | awk 'sub(/.* inet addr:/, "") {print $1}') # systray="$systray $ip_address" echo "$systray" # sysmon-indidicator will put echo string into systray for us. exit 0
通过设置每个刷新间隔运行的{Custom}
变量告诉Sysmonitor Indicator您的bash脚本的名称。 无论你的bash脚本通过echo
命令输出什么都出现在Ubuntu的系统托盘中。
注意:脚本显示剩余时间和显示亮度级别值。 这些值由Ask Ubuntu中记录的脚本设置: 应用程序将在Ubuntu 设定的时间后锁定屏幕,同时 设置不同警报的计时器 和分别根据日出和日落自动调整显示亮度 。
旋转披萨 – text-spinner
BASH脚本
text-spinner
bash脚本通过循环遍历字符来创建旋转披萨效果 , /
, ─
和\
。 这种效果突出了一些事实是“工作”或“思考”。 要获得“旋转效果”,您需要将Sysmonitor指示灯刷新间隔从默认的2
秒更改为大约0.30
秒。
这是text-spinner
bash脚本:
#!/bin/bash # return '|', '/', '─', '\' sequentially with each call to this script. # Use ~/.last-text-spinner to store last used FILE=~/.last-text-spinner if ! [ -f $FILE ]; then echo '|' > $FILE exit 124 # ASCII equivalent for '|'. Bash doesn't allow character return codes fi LAST=$(cat $FILE) # read last character used if [[ $LAST == '|' ]]; then echo '/' > $FILE exit 47 # ASCII equivalent of "/" elif [[ $LAST == '/' ]]; then # NOTE: you must have spaces around " == " else code breaks echo '─' > $FILE exit 9472 # ASCII equivalent elif [[ $LAST == '─' ]]; then echo '\' > $FILE # NOTE: must use single quote because double quote BASH reinterprets exit 92 # ASCII else echo '|' > $FILE exit 124 # ASCII fi