kdotool icon indicating copy to clipboard operation
kdotool copied to clipboard

Commands generate KWin scripts but always return OS error 2

Open lorods opened this issue 1 year ago • 1 comments

./kdotool --debug get_desktop

[2024-05-18T19:47:35Z DEBUG kdotool] ===== Generate KWin script ===== [2024-05-18T19:47:35Z DEBUG kdotool] Script: print("kdotool-wEHTOJ START");

function output_debug(message) {
    print("kdotool-wEHTOJ DEBUG", message);
    callDBus(":1.399", "/", "", "debug", message.toString());
}

function output_error(message) {
    print("kdotool-wEHTOJ ERROR", message);
    callDBus(":1.399", "/", "", "error", message.toString());
}

function output_result(message) {
    if (message == null) {
        print("kdotool-wEHTOJ RESULT null");
        return;
    }
    print("kdotool-wEHTOJ RESULT", message);
    callDBus(":1.399", "/", "", "result", message.toString());
}

workspace_windowList                  = () => workspace.windowList();
workspace_activeWindow                = () => workspace.activeWindow;
workspace_setActiveWindow             = (window) => { workspace.activeWindow = window; };
workspace_raiseWindow                 = (window) => { workspace.raiseWindow(window); };
workspace_currentDesktop              = () => workspace.currentDesktop.x11DesktopNumber;
workspace_setCurrentDesktop           = (id) => {
    let d = workspace.desktops.find((d) => d.x11DesktopNumber == id);
    if (d) {
        workspace.currentDesktop = d;
    } else {
        output_error(`Invalid desktop number ${id}`);
    }
};
workspace_numDesktops                 = () => workspace.desktops.length;
workspace_setNumDesktops              = (n) => { output_error("`set_num_desktops` unsupported in KDE 6"); };
window_x11DesktopIds                  = (window) => window.desktops.map((d) => d.x11DesktopNumber);
window_setX11DesktopId                = (window, id) => {
    let d = workspace.desktops.find((d) => d.x11DesktopNumber == id);
    if (d) {
        window.desktops = [d];
    } else {
        output_error(`Invalid desktop number ${id}`);
    }
};
window_screen                         = (window) => { output_error("`search --screen` unsupported in KDE 6"); };

function run() {
    var window_stack = [];

    output_debug("STEP get_desktop")
    output_result(workspace_currentDesktop());

}

run();

print("kdotool-wEHTOJ FINISH");

[2024-05-18T19:47:35Z DEBUG kdotool] ===== Load script into KWin ===== [2024-05-18T19:47:35Z DEBUG kdotool] Script ID: 0 [2024-05-18T19:47:35Z DEBUG kdotool] ===== Run script ===== [2024-05-18T19:47:35Z DEBUG kdotool] dbus message: Message { Type: MethodCall, Path: "/", Member: "debug", Sender: ":1.10", Destination: ":1.399", Serial: 3811, Args: ["STEP get_desktop"] } [2024-05-18T19:47:35Z DEBUG kdotool] dbus message: Message { Type: MethodCall, Path: "/", Member: "result", Sender: ":1.10", Destination: ":1.399", Serial: 3812, Args: ["1"] } Error: No such file or directory (os error 2)

lorods avatar May 18 '24 19:05 lorods

kdotool calls journalctl from systemd to fetch debug logs. So if you are not using systemd, it will fail. I'll add a test to handle this scenario.

Thanks for reporting this.

jinliu avatar May 20 '24 03:05 jinliu

Thanks for the heads up about this. I was struggling with this as well on a non-systemd system, even going so far as using strace to try to figure out what it's calling and could never find any reference to journalctl. I didn't think to just look at the source code. Commenting out the journaltcl stuff makes it work just fine.

Happy to be able to test this out, now. I've been struggling with finding a good xdotool replacement for wayland that can not only send keystrokes but also activate windows to target that output. kdotool is the only utility I've found so far that seems to be able to do this.

nitro322 avatar Sep 21 '24 16:09 nitro322

@nitro322 Glad this is useful for you. I also changed the code to not call journalctl unless --debug is specified. And it won't fail when journalctl is not found on --debug.

jinliu avatar Sep 22 '24 03:09 jinliu