Gil*_*il' 9 command-line x11 drag-and-drop freedesktop
我有时需要将文件拖放到应用程序上。(示例- 但我在这里的问题不是安装 Chrome 用户脚本。)一种解决方案是使用 Dragbox,它会打开一个窗口,我可以从中拖动命令行上指定的文件。
这很好,但我想减少必要的鼠标交互。使用 Dragbox,我必须: 安排 Dragbox 和放置区都可见;将鼠标光标移动到 Dragbox 显示文件的位置;按下鼠标左键;将鼠标光标移动到放置区;释放光标。
我想要一个更像复制粘贴的界面:运行类似 的命令dragbox --more-magic foo
,然后单击拖放区。或者运行命令然后聚焦拖放区并按下一个键。有没有程序可以做到这一点?甚至可以通过 Freedesktop 拖放来完成吗?
现在已经2019年了,但仍然...
这是我目前的截图工具。xdotool 命令与如何自动拖动文件相关。
这里是脚本(在示例中通过热键启动):
2.bin$ cat drag_into
#!/usr/bin/env bash
doc="$0 <filename|'shot'>
With filename: Drags given file to where the mouse is using dragon.
Click to drop it (anywere).
With 'shot' : File will be a shot of a an area to be selected.
=> 'drag_into shot' on a hotkey combo makes sense.
"
cmd_shot="shot"
file=
exit_help () { echo -e "$doc"; exit 1; }
select_shot_area () {
# create screen shot
notify-send "Select area - we'll shoot it and drag to where the mouse is."
cd "$HOME/Pictures/shots/" || exit 1
rm -f "latest.png"
scrot -s '%Y-%m-%d_$wx$h_scrot.png' -e 'ln -s $f latest.png'
file="`readlink latest.png`"
}
main () {
file="$1"
test -z "$file" -o "$file" == "-h" && exit_help
eval "$(xdotool getmouselocation --shell)" # into $X and $Y
test "$file" == "$cmd_shot" && { select_shot_area || return 1; }
killall dragon 2>/dev/null # No accidential drops of wrong items ...
dragon --and-exit "$file" &
while true; do
xid="$(xdotool search --onlyvisible --class dragon | head -n 2)"
test -z "$xid" || break
sleep 0.05
done
xdotool mousemove --sync -w "$xid" 1 1 mousedown 1 mousemove $X $Y
notify-send "Click to drop $file..."
}
main "$@"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1539 次 |
最近记录: |