Kde
如何從命令行執行 kwin 腳本?
我寫了一個非常基本的 kwin 腳本來平鋪我喜歡的視窗,
// Main reference: http://techbase.kde.org/Development/Tutorials/KWin/Scripting // Top-level parameters. Adjust these as suitable for your desktop. var width = 3840; var third = Math.round(width / 3); var clients = workspace.clientList(); for (var i=0; i<clients.length; i++) { var client = clients[i]; var cap = client.caption.toLowerCase(); var g = client.geometry; if (cap.indexOf("firefox") != -1) { g.x = 0; g.width = third; } else if (cap.indexOf("vim") != -1) { g.x = third; g.width = third; } else if (cap.indexOf("konsole") != -1) { g.x = third * 2; g.width = third; } client.geometry = g; }
使用腳本控制台(
qdbus org.kde.plasma-desktop /MainApplication showInteractiveKWinConsole
或wm console
來自 krunner)。我想將此綁定到熱鍵。
我只能找到關於建構 Plasma 包的資源,我還沒有開始工作(我有一個
metadata.desktop
類似於 中的那些/usr/share/kde4/apps/kwin/scripts
,以及類似的目錄內容,但它說plasmapkg(3980)/libplasma Plasma::Package::installPackage: Could not register package as service (this is not necessarily fatal): "kwin-script-tilewindows"
)。我有點厭倦了等離子包裝。如何從命令行呼叫基於 JavaScript 的 kwin 腳本?
編輯/注意
如果您不熟悉,在 KDE 中將命令綁定到熱鍵很容易——只需右鍵點擊應用程序啟動器,轉到“編輯應用程序”,添加一個新項目,在“命令”框中輸入 shell 命令,然後在“高級”選項卡中設置快捷鍵。
從這裡得到一些提示,我設法使以下工作:
script=/path/to/script num=$(dbus-send --print-reply --dest=org.kde.kwin.Scripting \ /Scripting \ org.kde.kwin.Scripting.loadScript \ string:"$script" | awk 'END {print $2}' ) dbus-send --print-reply --dest=org.kde.kwin.Scripting \ /$num \ org.kde.kwin.Scripting.run
更新:這是我在 2019 年必須做的才能讓它發揮作用:
# don't use ~/ in this path: script="/path/to/script" num=$(dbus-send --print-reply --dest=org.kde.KWin \ /Scripting org.kde.kwin.Scripting.loadScript \ string:"$script" | awk 'END {print $2}' ) dbus-send --print-reply --dest=org.kde.KWin /$num \ org.kde.kwin.Scripting.run