alw*_*btc 51 shell firefox window
我希望使用 shell 命令以特定大小和屏幕位置打开 Firefox 窗口,例如:
firefox myfile.html size 800x600 location bottom-left
Run Code Online (Sandbox Code Playgroud)
有这样的命令吗?
roa*_*ima 43
这是Yokai的答案的社区版本,其中包含了Rudolf Olah提供的示例。
您可以使用调用的工具xdotool来控制窗口大小和位置。不仅如此,你在写任何脚本bash,使用xdotool,可以设置为工作具有完全最大化的窗口,它可以编写脚本设置窗口大小和X:通过操控y坐标mousemove和click指令。
查找窗口 ID:
xdotool search --onlyvisible --name firefox
Run Code Online (Sandbox Code Playgroud)设置窗口大小
xdotool windowsize $WINDOW_ID_GOES_HERE $WIDTH $HEIGHT
Run Code Online (Sandbox Code Playgroud)移动窗口
xdotool windowmove $WINDOW_ID_GOES_HERE $X $Y
Run Code Online (Sandbox Code Playgroud)例如,如果 firefox 的窗口 ID 是 123,你可以这样做:
xdotool windowsize 123 800 600
xdotool windowmove 123 0 1080
Run Code Online (Sandbox Code Playgroud)
必须根据您的屏幕分辨率确定左下角的位置。
Bob*_*bby 20
据我所知,这是不可能的,因为 Firefox 不接受控制窗口的命令。这也是(主要)窗口管理器的责任,所以我怀疑是否会有参数来做到这一点。但是,您可以使用wmctrl控制窗口,但这会有点困难:
#!/usr/bin/env bash
firefox -new-instance -new-window "http://www.reddit.org" &
# Process ID of the process we just launched
PID=$!
# Window ID of the process...pray that there's
# only one window! Otherwise this might break.
# We also need to wait for the process to spawn
# a window.
while [ "$WID" == "" ]; do
WID=$(wmctrl -lp | grep $PID | cut "-d " -f1)
done
# Set the size and location of the window
# See man wmctrl for more info
wmctrl -i -r $WID -e 0,50,50,250,250
Run Code Online (Sandbox Code Playgroud)
可能有更聪明的方法来做到这一点,并且与 Firefox 存在一些互操作性问题(例如,没有其他实例正在运行),但它应该可以帮助您前进。