bianjp/popup-dict-switcher

希望添加启动和关闭的快捷键

Opened this issue · 2 comments

l0o0 commented

不知道可不可以有快捷键功能 ,感觉这样会更方便一些

有打算实现 status/start/stop/restart/toggle 等管理命令,这样就能通过桌面环境的快捷键管理功能自己添加快捷键了。不过需要对程序入口做较大改动,之前没想到合适的代码组织形式,搁置了,有空我会再考虑下。

Thanks for bianjp's great work!

Use following script and bind your customized hot key may help.

#!/bin/sh

PS_KEYWORD=popup-dict
PS_KEYWORD0=python3
PROCESS=/usr/local/bin/popup-dict

case $1 in
	start)
		ps aux |grep -v grep | grep ${PS_KEYWORD} | grep ${PS_KEYWORD0} -q
			if [ $? -ne 0 ]; then
				${PROCESS} 2>&1 > /dev/null &
				export DISPLAY=:0.0 && /usr/bin/notify-send -i accessories-dictionary "On" "popup-dict on"
			fi
		;;

	stop)
		for pid in `pidof ${PS_KEYWORD0}`;do 
			grep -q ${PS_KEYWORD} /proc/${pid}/cmdline
			if [ $? -eq 0 ]; then
				export DISPLAY=:0.0 && /usr/bin/notify-send -i accessories-dictionary "Off" "popup-dict off"
				kill ${pid}
			fi
		done;
		;;
        switch)
                ps aux |grep -v grep | grep ${PS_KEYWORD} | grep ${PS_KEYWORD0} -q
                        if [ $? -ne 0 ]; then
                                #if offline, turn it on
                                $0 start
                        else
                                #else online, turn it off
                                $0 stop
                        fi
                ;;

	restart)
		$0 stop
		sleep 1
		$0 start
		;;
esac

exit 0