[software development] 分享微信4.0Linux版本设置快捷键ctrl+shift+w的方法
Tofloor
poster avatar
竹子
deepin
2025-01-20 15:55
Author

使用xdotool

注意TASKBAR_ICON_X,TASKBAR_ICON_Y是通过xdotool getmouselocation获取鼠标位置得到坐标,需要根据实际情况更改,获取位置方式:

在命令窗口输入命令 “xdotool getmouselocation”——将鼠标移动到微信图标上(需将微信图标拖到右下角的状态栏常驻,最好保持固定位置,否则得调整位置)——回车获取鼠标位置

#!/bin/sh

active=$(xdotool getactivewindow)

for item in $(pgrep "$1" | xargs -I {} xdotool search --all --pid {})
do
    if test $active -eq $item
    then
        xdotool windowminimize $item
        #echo "关闭当前活动窗口的 ID 为 $item"
    else
        xdotool windowactivate $item
        nowWindow=$(xdotool getactivewindow)
        if test $nowWindow -ne $item
        then
            CURRENT_X=$(xdotool getmouselocation | awk '{print $1}' | cut -d ':' -f 2)
            CURRENT_Y=$(xdotool getmouselocation | awk '{print $2}' | cut -d ':' -f 2)
            TASKBAR_ICON_X=1682
            TASKBAR_ICON_Y=1060
            #echo "当前窗口未打开,尝试模拟点击托盘图标:X=$TASKBAR_ICON_X, Y=$TASKBAR_ICON_Y"
            xdotool mousemove $TASKBAR_ICON_X $TASKBAR_ICON_Y
            xdotool click 1
            xdotool mousemove $CURRENT_X $CURRENT_Y
        fi
    fi
done
  • 创建如上脚本放到一个目录下,如/home/username/MyShell/openWindow.sh
  • 给脚本授权
sudo chmod -R +x openWindow.sh
  • 创建快捷键,命令如下,快捷键和名称可以自己定义
/home/username/MyShell/openWindow.sh "wechat"

图片.png

Reply Favorite View the author
All Replies
鲜衣怒马
deepin
2025-01-20 18:03
#1

agree

点赞技术贴

Reply View the author
liuhongwei11
deepin
2025-01-21 12:07
#2

好贴,学习了,感谢分享

Reply View the author