听起来很简单;xdotool
选择桌面,模拟F5按键并将焦点返回到调用窗口/程序。
谷歌搜索后虽然听起来不再简单。
我需要从 bash / gnome-shell 执行此操作。
有任何想法吗?
这个项目与这个 Q&A 相关,因为不同尺寸的显示器,图标从左边的屏幕掉成一个黑色的整体:
感谢Podesta 的帮助,我创建了此代码:
TestIcons () {
[[ $TestSeconds == "" ]] || [[ $TestSeconds == 0 ]] && TestSeconds=5
local i Position File
for (( i=0; i<${#IconsArr[@]}; i=i+ICON_FLD_CNT )) ; do
File="$ICONS_DIR"/"${IconsArr[((i+ICON_NAME_NDX))]}"
Position="${IconsArr[((i+ICON_COL_NDX))]},${IconsArr[((i+ICON_ROW_NDX))]}"
gvfs-set-attribute -t string "$File" \
'metadata::nautilus-icon-position' "$Position"
done
wmctrl -k on # Show desktop
xdotool key F5 # Refresh desktop (show icon new positions)
sleep $TestSeconds # Pause for view
wmctrl -k off # Restore windows
for (( i=0; i<${#OldIconsArr[@]}; i=i+ICON_FLD_CNT )) ; do
File="$ICONS_DIR"/"${OldIconsArr[((i+ICON_NAME_NDX))]}"
Position="${OldIconsArr[((i+ICON_COL_NDX))]},${OldIconsArr[((i+ICON_ROW_NDX))]}"
gvfs-set-attribute -t string "$File" \
'metadata::nautilus-icon-position' "$Position"
done
wmctrl -k on # Show desktop
xdotool key F5 # Refresh desktop (show icon new positions)
wmctrl -k off # Restore windows
} # TestIcons
这是屏幕的样子:
Script below work of @WinEunuuchs2Unix and is the final solution. My original answer is at the end.
#!/bin/bash
TestIcons () {
[[ $TestSeconds == "" ]] || [[ $TestSeconds == 0 ]] && TestSeconds=5
local i Position File
for (( i=0; i<${#IconsArr[@]}; i=i+ICON_FLD_CNT )) ; do
File="$ICONS_DIR"/"${IconsArr[((i+ICON_NAME_NDX))]}"
Position="${IconsArr[((i+ICON_COL_NDX))]},${IconsArr[((i+ICON_ROW_NDX))]}"
gvfs-set-attribute -t string "$File" \
'metadata::nautilus-icon-position' "$Position"
done
wmctrl -k on # Show desktop
xdotool key F5 # Refresh desktop (show icon new positions)
sleep $TestSeconds # Pause for view
wmctrl -k off # Restore windows
for (( i=0; i<${#OldIconsArr[@]}; i=i+ICON_FLD_CNT )) ; do
File="$ICONS_DIR"/"${OldIconsArr[((i+ICON_NAME_NDX))]}"
Position="${OldIconsArr[((i+ICON_COL_NDX))]},${OldIconsArr[((i+ICON_ROW_NDX))]}"
gvfs-set-attribute -t string "$File" \
'metadata::nautilus-icon-position' "$Position"
done
wmctrl -k on # Show desktop
xdotool key F5 # Refresh desktop (show icon new positions)
wmctrl -k off # Restore windows
}
TestIcons
A few other xdotools
commands that can be useful in similar situation:
If your window manager has a show desktop command, it can be useful to minimize, and bring back all windows. Usually it is set to ctrl+alt+d
:
xdotool key ctrl+alt+d
If you want to save the currently active window, to later bring it back, you can use:
myWindow="$(xdotool getactivewindow)"
Ti minimize a window you can use. Adding it to a loop allows you to minimize all windows, as an alternative to the show dekstop.
xdotool windowminimize $(xdotool getactivewindow)
To bring the active window you saved back to the focus:
xdotool windowactivate "$myWindow"
To close the active window use:
xdotool getactivewindow windowkill
最重要的是,您可以在活动窗口中使用所有这些命令,您实际上可以搜索并应用于特定情况。例如,根据标题搜索此特定窗口。
xdotool search --desktop 0 --name "command line - xdotool" windowactivate
有许多不同的搜索窗口的方法,基于标题、类别、它们是否可见等。它还可以操作窗口位置和鼠标。xdotol 的联机帮助页非常全面。将它们与 bash 脚本结合起来可以为实现大多数事情提供足够的自由。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句