我使用 Linux Mint 18.3 Cinnamon 64 位。我已经xdotool
安装了。
光射自登录以来一直在运行,我使用启动应用程序工具在登录后立即创建启动:
env WINEPREFIX="/home/vlastimil/.lightshot" wine C:\\windows\\command\\start.exe /Unix /home/vlastimil/.lightshot/dosdevices/c:/users/Public/Start\ Menu/Programs/Lightshot/Lightshot.lnk
目标:
按PrtSc(打印屏幕键)并进入全屏剪切模式(事实上,与 Windows 下的 Lightshot 具有相同的功能)。
什么有效(当从运行时gnome-terminal
):
xdotool key --window $(xdotool search --limit 1 --all --pid $(pgrep Lightshot) --name Lightshot) "Print"
但是,如果将其复制粘贴到添加自定义快捷方式对话框:
我只是想知道为什么会这样,更重要的是,如何让它发挥作用?
答案1
2020 年 1 月 2 日更新
您可以找到最新修订版和使用说明在它的 GitHub 页面。
原帖
原因可能是,我没有指定要运行的任何 shell,因此以下内容有效:
sh -c 'xdotool key --window $(xdotool search --limit 1 --all --pid $(pgrep Lightshot) --name Lightshot) "Print"'
编辑:
可能值得注意的是,我现在决定为其编写一个脚本。充分验证每一步:
#!/bin/sh
is_number()
{
# check if exactly one argument has been passed
test "$#" -eq 1 || print_error_and_exit 5 "is_number(): There has not been passed exactly one argument!"
# check if the argument is an integer
test "$1" -eq "$1" 2>/dev/null
}
# ------------------------------------------------------------------------------
print_error_and_exit()
{
# check if exactly two arguments have been passed
test "$#" -eq 2 || print_error_and_exit 3 "print_error_and_exit(): There have not been passed exactly two arguments!"
# check if the first argument is a number
is_number "$1" || print_error_and_exit 4 "print_error_and_exit(): The argument #1 is not a number!"
# check if we have color support
if [ -x /usr/bin/tput ] && tput setaf 1 > /dev/null 2>&1
then
bold=$(tput bold)
red=$(tput setaf 1)
nocolor=$(tput sgr0)
echo "$bold$red$2 Exit code = $1.$nocolor" 1>&2
else
echo "$2 Exit code = $1." 1>&2
fi
exit "$1"
}
# ------------------------------------------------------------------------------
check_for_prerequisite()
{
# check if exactly one argument has been passed
test "$#" -eq 1 || print_error_and_exit 2 "check_for_prerequisite(): There has not been passed exactly one argument!"
# check if the argument is a program which is installed
command -v "$1" > /dev/null 2>&1 || print_error_and_exit 6 "check_for_prerequisite(): I require $1 but it's not installed :-("
}
# ------------------------------------------------------------------------------
# check if no arguments have been passed to the script
test "$#" -gt 0 && print_error_and_exit 1 "$0: You have passed some unexpected argument(s) to the script!"
# ------------------------------------------------------------------------------
# check for prerequisites
check_for_prerequisite "pgrep"
check_for_prerequisite "xdotool"
# ------------------------------------------------------------------------------
# global constants
lightshot_key="Print"
lightshot_name="Lightshot"
# ------------------------------------------------------------------------------
# get the lightshot pid
lightshot_pid=$(pgrep "$lightshot_name")
# test if a pid has been successfully acquired
is_number "$lightshot_pid" || print_error_and_exit 7 "lightshot_pid: The argument is not a number!\\nLightshot is most probably not running."
# ------------------------------------------------------------------------------
# get the window id from lightshot pid
lightshot_wnd=$(xdotool search --limit 1 --all --pid "$lightshot_pid" --name "$lightshot_name")
# test if a window handler has been successfully acquired
is_number "$lightshot_wnd" || print_error_and_exit 8 "lightshot_wnd: The argument is not a number!\\nLightshot is most probably not running."
# ------------------------------------------------------------------------------
# simulate a print screen key press on the lightshot window
xdotool key --window "$lightshot_wnd" "$lightshot_key"