たくさんのプログラムを開き、画面上のウィンドウを移動/サイズ変更するスクリプトを作成しようとしています。
例えば、
#!/bin/bash
zim
wmctrl -r Zim -b toggle,maximized_vert
wmctrl -r Zim -e 0,700,0,-1,-1
このスクリプトを実行すると、ウィンドウが最大化され、少し右に移動します。私は交換した場合でも、zim
によってfirefox
またはacroread
、これは、ウィンドウのサイズを変更/移動に失敗しました。
wmctrl
ターミナルに入力すれば機能しますが、スクリプト内で使用したいのですが。firefox
画面上の位置を覚える方法と関係があるのではないかと思います。
編集:私は配置しました
firefox
wmctrl -lG
スクリプト内で、次の出力が得られます。
0x03800032 0 1168 347 750 731 briareos emacs@briareos
0x02a00002 0 -2020 -1180 1920 1080 briareos XdndCollectionWindowImp
0x02a00005 0 0 24 47 1056 briareos unity-launcher
0x02a00008 0 0 0 1920 24 briareos unity-panel
0x02a0000b 0 -420 -300 320 200 briareos unity-dash
0x02a0000c 0 -420 -300 320 200 briareos Hud
0x03c00011 0 59 52 900 1026 briareos Notes - Zim
これは、スクリプトがFirefoxが起動されたことを認識していないことを意味します。
問題は、使用するコマンドの組み合わせで、wmctrl
コマンドが成功するためには、アプリケーションのウィンドウが時間内に表示されるように「幸運」である必要があるということです。
コマンドは、軽いアプリケーションではほとんどの場合機能し、すぐに起動しますが、Inkscape、Firefox、Thunderbirdなどの他のアプリケーションでは機能しません。
(コメントで述べたように)5秒または10秒の休憩を組み込むことができますが、必要以上に長く待たなければならないか、プロセッサが占有されていてウィンドウが「より遅い」場合は結局休憩します。いつもの」。
解決策は、スクリプトにプロシージャを含め、ウィンドウがの出力に表示されるのを待ってからwmctrl -lp
、コマンドを実行してウィンドウを最大化することです。
python
以下の例ではxdotool
、ウィンドウのサイズを変更するために使用しwmctrl
ました。これは、仕事をするよりも少し堅牢です。
#!/usr/bin/env python3
import subprocess
import getpass
import time
import sys
app = sys.argv[1]
# to only list processes of the current user
user = getpass.getuser()
get = lambda x: subprocess.check_output(x).decode("utf-8")
# get the initial window list
ws1 = get(["wmctrl", "-lp"]); t = 0
# run the command to open the application
subprocess.Popen(app)
while t < 30:
# fetch the updated window list, to see if the application's window appears
ws2 = [(w.split()[2], w.split()[0]) for w in get(["wmctrl", "-lp"]).splitlines() if not w in ws1]
# see if possible new windows belong to our application
procs = sum([[(w[1], p) for p in get(["ps", "-u", user]).splitlines() \
if app[:15].lower() in p.lower() and w[0] in p] for w in ws2], [])
# in case of matches, move/resize the window
if len(procs) > 0:
subprocess.call(["xdotool", "windowsize", "-sync", procs[0][0] , "100%", "100%"])
break
time.sleep(0.5)
t = t+1
このスクリプトは、両方を必要とするwmctrl
とxdotool
:
sudo apt-get install wmctrl xdotool
スクリプトを空のファイルにコピーし、名前を付けて保存します resize_window.py
アプリケーションを引数としてスクリプトをテスト実行します。例:
python3 /path/to/resize_window.py firefox
wmctrl
、ウィンドウリストをフェッチするコマンドの実行が早すぎる可能性がわずかにあります。問題が発生した場合は、手順全体にtry
/を追加する必要がありexcept
ます。もしそうなら、私に知らせてください。この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加