我目前分配我的thinkvantage按钮关闭点击我的触控板,但我想把它转换为一个开关开关。
目前,这是我用来关闭它的bash命令(或使用CTRL):
gsettings set org.gnome.settings-daemon.peripherals.touchpad tap-to-click true
gsettings set org.gnome.settings-daemon.peripherals.touchpad tap-to-click false换句话说,我会把它变成一个条件切换开关bash语句吗?
发布于 2015-02-18 16:16:38
大概是这样的:
#!/bin/bash
class=org.gnome.settings-daemon.peripherals.touchpad
name=tap-to-click
status=$(gsettings get "$class" "$name")
status=${status,,} # normalize to lower case; this is a modern bash extension
if [[ $status = true ]]; then
new_status=false
else
new_status=true
fi
gsettings set "$class" "$name" "$new_status"把它分解成碎片:
#!/bin/bash确保此脚本的解释器是bash,从而启用扩展语法(如[[ ]] )。$( )是“命令替换”;这将运行一个命令,并替换该命令的输出。因此,如果输出是true,那么status=$(...)就变成status=true。${name,,}扩展name的内容,同时将这些内容转换为全小写,并且只能在更新的bash版本中使用。如果您希望支持/bin/sh或较早版本的bash,可以考虑使用status=$(printf '%s\n' "$status" | tr '[:upper:]' '[:lower:]'),或者如果gsettings get的输出始终是小写的,则只需删除这一行。[[ $status = true ]]依赖于bash扩展[[ ]] (在其他现代ksh派生的shell中也可用)来避免引用。如果您想让它与#!/bin/sh一起工作,则应该使用[ "$status" = true ]。(请注意,==在[[ ]]中是允许的,但是对于纯POSIX shell,在[ ]中是不允许的;这就是为什么最好不要习惯使用它)。请注意,空格在bash!foo = bar中很重要,foo= bar和foo=bar是完全不同的语句,它们所做的事情都不同于其他两种语句。请务必认识到从此示例复制的差异。
发布于 2016-12-19 18:08:06
在Ubuntu统一时钟上切换秒(直接作为键绑定的命令传递):
bash -c 'gsettings set com.canonical.indicator.datetime show-seconds $(gsettings get com.canonical.indicator.datetime show-seconds | perl -neprint/true/?false:true)'
对于侏儒:
bash -c 'gsettings set org.gnome.desktop.interface clock-show-seconds $(gsettings get org.gnome.desktop.interface clock-show-seconds | perl -neprint/true/?false:true)'
发布于 2021-01-05 12:14:12
来源:https://www.commandlinefu.com/commands/view/24256/toggle-the-touchpad-on-or-off
synclient TouchpadOff=$(synclient -l | grep -q 'TouchpadOff.*1'; echo $?)或
tp=$(synclient -l | grep TouchpadOff | awk '{ print $3 }') && tp=$((tp==0)) && synclient TouchpadOff=$tphttps://stackoverflow.com/questions/28588147
复制相似问题