如何从命令行运行kwin脚本?


9

我写了一个非常基本的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命令,然后在“高级”标签中设置快捷键。

Answers:


7

这里得到一些提示,我设法完成了以下工作:

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

1

更新:这是我在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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.