SUMMARY Behavior of KWin scripts when using `plasma-interactiveconsole`. Missing globals when running commands. I found this when trying to fix a script I had working on Plasma 5 and decided to debug it with `plasma-interactiveconsole`. I can't confirm the reason my script isn't working when packaged and loaded into Plasma but the behavior since both don't work (JS Error in `plasma-interactiveconsole` and nothing observed when loaded into plasma). I can't find workspace either on `this` context or as a global as shown with script below. STEPS TO REPRODUCE 1. Open `plasma-interactiveconsole` 2. Run the following script ``` for (let key in this) // expected 'registerShortcut' and 'workspace' to be keys here print(key + ' - ' + this[key] + '\n') print('\n') print('\n') for (let key in __AppInterface) print(key + ' - ' + this[key] + '\n') print('\n') print('\n') print('registerShortcut: ' + typeof registerShortcut + '\n') // expected function here print('workspace: ' + typeof workspace + '\n') // expected some object with properties here ``` OBSERVED RESULT __AppInterface - WorkspaceScripting::AppInterface(0x56d3925a4340) screenGeometry - function() { [native code] } lockCorona - function() { [native code] } sleep - function() { [native code] } print - function() { [native code] } getApiVersion - function() { [native code] } __newPanel - function() { [native code] } __newConfigFile - function() { [native code] } ConfigFile - function ConfigFile() { [native code] } Panel - function Panel() { [native code] } QRectF - function QRectF() { [native code] } createActivity - function() { [native code] } setCurrentActivity - function() { [native code] } currentActivity - function() { [native code] } activities - function() { [native code] } activityName - function() { [native code] } setActivityName - function() { [native code] } loadSerializedLayout - function() { [native code] } desktopsForActivity - function() { [native code] } desktops - function() { [native code] } desktopById - function() { [native code] } desktopForScreen - function() { [native code] } screenForConnector - function() { [native code] } panelById - function() { [native code] } panels - function() { [native code] } fileExists - function() { [native code] } loadTemplate - function() { [native code] } applicationExists - function() { [native code] } defaultApplication - function() { [native code] } userDataPath - function() { [native code] } applicationPath - function() { [native code] } knownWallpaperPlugins - function() { [native code] } gridUnit - 18 setImmutability - function() { [native code] } immutability - function() { [native code] } i18n - function() { [native code] } i18nc - function() { [native code] } i18np - function() { [native code] } i18ncp - function() { [native code] } i18nd - function() { [native code] } i18ndc - function() { [native code] } i18ndp - function() { [native code] } i18ndcp - function() { [native code] } xi18n - function() { [native code] } xi18nc - function() { [native code] } xi18np - function() { [native code] } xi18ncp - function() { [native code] } xi18nd - function() { [native code] } xi18ndc - function() { [native code] } xi18ndp - function() { [native code] } xi18ndcp - function() { [native code] } locked - false hasBattery - true screenCount - 3 activityIds - 1,2,36,61,120,155,156,157,158,159,160,161,162,163,164,165,166,167,168,171,172,173,174,175,176,177,178,179,180,181,190 panelIds - 26,113,182 knownPanelTypes - org.kde.panel knownActivityTypes - org.kde.desktopcontainment,org.kde.plasma.folder knownWidgetTypes - org.kde.plasma.simplekickoff,com.himdek.kde.plasma.overview,com.github.boraerciyas.controlcentre,org.kde.plasma.pager,org.kde.plasma.activitypager,org.kde.plasma.trash,org.kde.plasma.systemmonitor.diskactivity,org.kde.plasma.activitybar,org.kde.plasma.kickerdash,org.kde.plasma.systemmonitor.memory,org.kde.plasma.webbrowser,org.kde.plasma.private.grouping,org.kde.plasma.icontasks,org.kde.plasma.printmanager,org.kde.plasma.diskquota,org.kde.plasma.analogclock,org.kde.plasma.systemmonitor.net,org.kde.plasma.kicker,org.kde.plasma.userswitcher,org.kde.plasma.cameraindicator,org.kde.plasma.keyboardindicator,org.kde.panel,org.kde.plasma.systemmonitor.cpucore,org.kde.plasma.brightness,org.kde.desktopcontainment,org.kde.plasma.quicklaunch,org.kde.plasma.marginsseparator,org.kde.plasma.addons.katesessions,org.kde.plasma.fifteenpuzzle,org.kde.plasma.icon,org.kde.plasma.networkmanagement,org.kde.plasma.keyboardlayout,org.kde.plasma.showdesktop,org.kde.plasma.folder,org.kde.kscreen,org.kde.plasma.showActivityManager,org.kde.plasma.panelspacer,org.kde.plasma.weather,org.kde.plasma.lock_logout,org.kde.plasma.notes,org.kde.plasma.comic,org.kde.plasma.konsoleprofiles,org.kde.plasma.colorpicker,org.kde.plasma.kimpanel,org.kde.plasma.devicenotifier,org.kde.plasma.private.systemtray,org.kde.plasma.fuzzyclock,org.kde.plasma.mediaframe,org.kde.plasma.battery,org.kde.plasma.timer,org.kde.plasma.binaryclock,org.kde.plasma.notifications,org.kde.milou,org.kde.plasma.grouping,org.kde.plasma.minimizeall,org.kde.plasma.systemmonitor,org.kde.plasma.kickoff,org.kde.plasma.calendar,org.kde.plasma.volume,org.kde.plasma.clipboard,org.kde.plasma.systemtray,org.kde.plasma.calculator,org.kde.plasma.mediacontroller,org.kde.plasma.manage-inputmethod,org.kde.plasma_applet_dict,org.kde.plasma.bluetooth,org.kde.plasma.digitalclock,org.kde.plasma.systemmonitor.cpu,org.kde.plasma.taskmanager,org.kde.plasma.appmenu,org.kde.kdeconnect,org.kde.plasma.vault,org.kde.plasma.systemmonitor.diskusage,org.kde.plasma.windowlist theme - Gently applicationVersion - 6.0.3 platformVersion - scriptingVersion - 20 multihead - false multiheadScreen - false locale - en_US language - English languageId - en objectName - undefined locked - false hasBattery - true screenCount - 3 activityIds - 1,2,36,61,120,155,156,157,158,159,160,161,162,163,164,165,166,167,168,171,172,173,174,175,176,177,178,179,180,181,190 panelIds - 26,113,182 knownPanelTypes - org.kde.panel knownActivityTypes - org.kde.desktopcontainment,org.kde.plasma.folder knownWidgetTypes - org.kde.plasma.simplekickoff,com.himdek.kde.plasma.overview,com.github.boraerciyas.controlcentre,org.kde.plasma.pager,org.kde.plasma.activitypager,org.kde.plasma.trash,org.kde.plasma.systemmonitor.diskactivity,org.kde.plasma.activitybar,org.kde.plasma.kickerdash,org.kde.plasma.systemmonitor.memory,org.kde.plasma.webbrowser,org.kde.plasma.private.grouping,org.kde.plasma.icontasks,org.kde.plasma.printmanager,org.kde.plasma.diskquota,org.kde.plasma.analogclock,org.kde.plasma.systemmonitor.net,org.kde.plasma.kicker,org.kde.plasma.userswitcher,org.kde.plasma.cameraindicator,org.kde.plasma.keyboardindicator,org.kde.panel,org.kde.plasma.systemmonitor.cpucore,org.kde.plasma.brightness,org.kde.desktopcontainment,org.kde.plasma.quicklaunch,org.kde.plasma.marginsseparator,org.kde.plasma.addons.katesessions,org.kde.plasma.fifteenpuzzle,org.kde.plasma.icon,org.kde.plasma.networkmanagement,org.kde.plasma.keyboardlayout,org.kde.plasma.showdesktop,org.kde.plasma.folder,org.kde.kscreen,org.kde.plasma.showActivityManager,org.kde.plasma.panelspacer,org.kde.plasma.weather,org.kde.plasma.lock_logout,org.kde.plasma.notes,org.kde.plasma.comic,org.kde.plasma.konsoleprofiles,org.kde.plasma.colorpicker,org.kde.plasma.kimpanel,org.kde.plasma.devicenotifier,org.kde.plasma.private.systemtray,org.kde.plasma.fuzzyclock,org.kde.plasma.mediaframe,org.kde.plasma.battery,org.kde.plasma.timer,org.kde.plasma.binaryclock,org.kde.plasma.notifications,org.kde.milou,org.kde.plasma.grouping,org.kde.plasma.minimizeall,org.kde.plasma.systemmonitor,org.kde.plasma.kickoff,org.kde.plasma.calendar,org.kde.plasma.volume,org.kde.plasma.clipboard,org.kde.plasma.systemtray,org.kde.plasma.calculator,org.kde.plasma.mediacontroller,org.kde.plasma.manage-inputmethod,org.kde.plasma_applet_dict,org.kde.plasma.bluetooth,org.kde.plasma.digitalclock,org.kde.plasma.systemmonitor.cpu,org.kde.plasma.taskmanager,org.kde.plasma.appmenu,org.kde.kdeconnect,org.kde.plasma.vault,org.kde.plasma.systemmonitor.diskusage,org.kde.plasma.windowlist theme - Gently applicationVersion - 6.0.3 platformVersion - scriptingVersion - 20 multihead - false multiheadScreen - false locale - en_US language - English languageId - en objectNameChanged - undefined print - function() { [native code] } screenGeometry - function() { [native code] } lockCorona - function() { [native code] } sleep - function() { [native code] } registerShortcut: undefined workspace: undefined EXPECTED RESULT SOFTWARE/OS VERSIONS Windows: macOS: Linux/KDE Plasma: (available in About System) KDE Plasma Version: KDE Frameworks Version: Qt Version: ADDITIONAL INFORMATION Running `plasma-interactiveconsole --kwin` does nothing with the output ``` Executing script at fimmtudagur, 18. apríl 2024 08:40:29 GMT Runtime: 1ms ```
I recently upgraded from Fedora 39 to 41. This upgraded my kde from version 5.something to 6.2.4. Since this upgrade my custom kwin scripts no longer work and it looks to be the same cause. My scripts depend on the function 'workspace.clientList()'. Since the upgrade I get errors on the console: kwin_scripting: /home/janssege/.local/share/plasma-interactiveconsole/interactiveconsoleautosave.js:1: error: Property 'clientList' of object KWin::QtScriptWorkspaceWrapper(0x5633d92a4090) is not a function I don't know if workspace has been replace with something else or whether this is a bug. I'd appreciate a workaround or a fix for this though.
I have been studying this some more. I have found the scripting interface has a few incompatible changes between KDE 5 and 6. I didn't find a comprehensive explanation of this, but there is a start of such a document here: https://invent.kde.org/plasma/kwin/-/wikis/Porting-your-scripts-to-KWin-6 As to the results of your test script, I have found the existence of the 'workspace' variable depends on the context in which you run the script. If you run it in the "Plasma" context, indeed it doesn't exist. However if you run it in the "KWin" context, it does exist. The problem with the "KWin" context is that it won't print output directly. You can only get output from it in the journal. And even there, the "print" command won't output anything. If you replace "print" with "console.info" the output can be filtered in the journal using journalctl -f QT_CATEGORY=js QT_CATEGORY=kwin_scripting I don't know if there's an equivalent way to get this info on distributions that don't use the systemd journal. Now for my specific problem, I had to replace "workspace.clientList()" with "workspace.windowList()" and "workspace.activeClient" with "workspace.activeWindow".