Bug 445058

Summary: kwin interactive console does not work
Product: [Plasma] kwin Reporter: Know Zero <knowzero>
Component: scriptingAssignee: KWin default assignee <kwin-bugs-null>
Status: ASSIGNED ---    
Severity: normal CC: andy, ashark, info, kde, kdebugs, ken, kmcwilliampublic, m.weghorn, natalie_clarius, nate, postix, ppwwyyxxc, v, zawertun, zrenfire
Priority: NOR    
Version: 5.27.5   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=477069
Latest Commit: Version Fixed In:
Attachments: The not bold timedate text at first launch

Description Know Zero 2021-11-06 04:28:12 UTC
SUMMARY
Using the plasma-interactiveconsole --kwin , I go to kwin option on top. Then copy and paste the examples from here:

https://develop.kde.org/docs/plasma/kwin/#quick-start-desktop-console

They don't work. It says executed but nothing shows. I tried simple console.log or print and they also don't work. I even tried a syntax error by typing gibberish and it still says executed with nothing outputting.

The Plasma tab works, but it doesn't have access to the kwin api.

STEPS TO REPRODUCE
1.  Launch plasma-interactiveconsole --kwin
2.  Pick kwin in the top tab
3.  write anything
4. Execute

OBSERVED RESULT

Executing script at Saturday, November 6, 2021 12:16:10 AM EDT

Runtime: 11ms

But nothing shows up

EXPECTED RESULT

Any output!

SOFTWARE/OS VERSIONS
Linux/KDE Plasma:  OpenSuse Leap 15.3 KDE X11
KDE Plasma Version: 5.23.2
KDE Frameworks Version:  5.87.0
Qt Version: 5.15.2
Comment 1 Nate Graham 2021-11-08 21:32:48 UTC
Can confirm.
Comment 2 qq6fHY79E45suV 2021-11-18 18:06:32 UTC
I just switched to Plasma from Gnome after they broke my workflow AGAIN(!!!) with the latest update. I am trying to port my GJS scripts to KWin and just ran into this. Oops :-(
Comment 3 qq6fHY79E45suV 2021-11-18 18:08:17 UTC
(In reply to qq6fHY79E45suV from comment #2)
> I just switched to Plasma from Gnome after they broke my workflow AGAIN(!!!)
> with the latest update. I am trying to port my GJS scripts to KWin and just
> ran into this. Oops :-(

I just noticed the platform the bug is registered under. I'm using the latest Neon.
Comment 4 Chris Holland 2022-01-17 02:18:12 UTC
I just noticed in OpenSUSE Tumbleweed (kwin 5.23.5) that the kwin print output and errors are printed to the system journal. Use:
journalctl -b0 -f
Comment 5 Andrew Shark 2022-05-18 20:38:29 UTC
This `journalctl -b0 -f` cannot print the output from script in interactive console, right?
Comment 6 Natalie Clarius 2022-05-18 21:33:42 UTC
(In reply to Andrew Shark from comment #5)
> This `journalctl -b0 -f` cannot print the output from script in interactive
> console, right?

Yes, it can.

But that output contains a lot of other stuff to. A more specific command to retreive output from JavaScript-based KWin and Plasmshell scripting is:

> journalctl -g "js:" -f
Comment 7 Andrew Shark 2022-05-18 21:52:21 UTC
Hmm, it just plainly does not work for me. The latter command is just silent. The script in interactive console is just `print("Hello")`. What else I can check? I am on Arch Linux if that matters. I see the same result (no output) in the post https://www.reddit.com/r/kde/comments/qo1jtj/kwin_scripting_console_not_working/.
Comment 8 Chris Holland 2022-05-19 00:17:53 UTC
The systemd logs printed in journalctl is just capturing the kwin_x11 output. It's possible that your distro doesn't capture the terminal output, or kwin restarted somehow. The journalctl workaround works fine for me OpenSUSE Tumbleweed Plasma 5.24.5.

Another workaround is to open Konsole, and run the following to restart kwin and log it's output to the Konsole window.
kstart5 -- kwin_x11 --replace

`kwin_x11 --replace` is the actual command, but `kstart5` will keep kwin running after you close Konsole. The `--` tells kstart5 to treat everything after it as a single argument (the command to run).
Comment 9 Natalie Clarius 2022-05-19 00:58:00 UTC
(In reply to Andrew Shark from comment #7)
> Hmm, it just plainly does not work for me. The latter command is just
> silent. The script in interactive console is just `print("Hello")`. What
> else I can check? I am on Arch Linux if that matters. I see the same result
> (no output) in the post
> https://www.reddit.com/r/kde/comments/qo1jtj/
> kwin_scripting_console_not_working/.

Are you on Wayland? Then logging might not work. Consider using systemd boot: https://invent.kde.org/plasma/plasma-workspace/-/wikis/Plasma-and-the-systemd-boot
Comment 10 Natalie Clarius 2022-05-19 01:13:54 UTC
Also make sure that you have logging for KWin scripts enabled:

> export QT_LOGGING_RULES='js=true; kwin_scripting=true'
Comment 11 Andrew Shark 2022-05-19 01:23:21 UTC
Wow, that worked now. Without QT_LOGGING_RULES. I can now see `... kwin_wayland[994]: js: Hello` messages in journal.
Thank you very much!
Comment 12 Andrew Shark 2022-05-19 01:29:01 UTC
For google searchers. I looked here https://wiki.archlinux.org/title/KDE#systemd_startup and to ensure you have enabled systemd startup, use `systemctl --user status plasma-plasmashell.service`. If it is active, it is working.
Comment 13 hexchain 2022-07-31 14:28:14 UTC
It is also possible to use "console.info" if you are too lazy to modify environment variables and re-login, like me.
Comment 14 Bug Janitor Service 2023-07-03 15:05:18 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/3042
Comment 15 Andrew Shark 2023-07-14 03:04:38 UTC
I also noticed that at first run, the datetime is not bold (expected: bold as all other launches).
Comment 16 Andrew Shark 2023-07-14 03:06:22 UTC
Created attachment 160274 [details]
The not bold timedate text at first launch
Comment 17 Kristen McWilliam 2023-10-04 15:12:08 UTC
I can confirm what @hexchain says, `console.info` works - for me nothing else was producing output at all, but this finally did.
Comment 18 Geert Janssens 2023-10-11 08:42:10 UTC
It took me a while to figure out that "console.info" in comment 13 was meant to be used instead of "print" in the scripts...

That does indeed work.
Comment 19 andy 2023-12-10 01:57:15 UTC
The workaround isn't super reliable working with the journal. Almost always the output is in the journal immediately after the dbus calls, but occasionally I find it's delayed by some milliseconds. So you have to poll or retry.

A bigger issue is you can't have multiple scripts running in parallel since it's this global journal output. You'd have to add some tag to each print statement to make sure you grep output from the right script only.