Unable to install KWin script

When installing a KWin script from the command line, I get

$ kpackagetool6 -t KWin/Script -i ~/tmp/test
qt.dbus.integration: QDBusConnection: error: could not send signal to service "" path "/KPackage/" interface "org.kde.plasma.kpackage" member "packageInstalled": Invalid object path: /KPackage/
Successfully installed /home/user/.local/share/kwin/scripts/test/

Even though, it says Successfully installed, and appears in the list of installed scripts in System Settings/KWin Scripts,

  • When I activate the script from the GUI, I get kwin_wayland[204637]: Could not find script file for "test4"in journalctl
  • When I deactivate it and
    • try to delete it from the GUI, I get Error when uninstalling KWin Script: package path was deleted manually
    • try do delete it with the kpackagetool6 -t KWin/Script -r test4 command, I get Error: Plugin is not installed.
  • The script does not run (no β€œtest5” log message in journalctl)

Any idea what’s wrong? It used to work, and I don’t remember changing anything…

If I try installing the script using the System Settings GUI, the file picker does not find any file to install.

This is the contents of the script folder:

$ tree ~/tmp/test
/home/user/tmp/test
└── package
    β”œβ”€β”€ contents
    β”‚   └── code
    β”‚       └── main.js
    └── metadata.json

$ cat ~/tmp/test/package/metadata.json 
{
    "KPlugin": {
        "Name": "test1",
        "Description": "test2",
        "Icon": "preferences-system-windows-script-test",

        "Authors": [
            {
                "Name": "test3"
            }
        ],
        "Id": "test4",
        "Version": "0.1",
        "License": "GPL-2.0+"
    },
    "X-Plasma-API": "javascript",
    "X-Plasma-MainScript": "code/main.js",
    "KPackageStructure": "KWin/Script"
}

$ cat ~/tmp/test/package/contents/code/main.js 
console.log("test5");

ur install root looks nested wrong. metadata.json is under package/ and Id is test4 while the folder is test, so kwin looks for a script file that isnt there.

id try:
-make a flat folder named the same as Id
test4/
metadata.json
contents/code/main.js
-kpackagetool6 -t KWin/Script -r test
-kpackagetool6 -t KWin/Script -r test4
-kpackagetool6 -t KWin/Script -i /path/to/test4

the dbus Invalid object path line is usually noise if it still says Successfully installed.

gui picker wants a .kwinscript zip, not a loose tree:
-cd /path/to/test4
-zip -r ../test4.kwinscript .
then install that zip in System Settings β†’ KWin Scripts.

after enable:
-journalctl -f | grep test5

Thanks! the extra nesting within the package folder was the culprit, indeed. With the structure below, it works fine

$ tree ~/tmp/test
/home/user/tmp/test
β”œβ”€β”€ contents
β”‚   └── code
β”‚       └── main.js
└── metadata.json

Note that the root folder name (~/tmp/test) being different than the script’s Id (test4) does not seem to matter. So, for example with the problematic structure I had before following your advice,

$ tree ~/tmp/test
/home/user/tmp/test
└── package
    β”œβ”€β”€ contents
    β”‚   └── code
    β”‚       └── main.js
    └── metadata.json

this works as well:

$ kpackagetool6 -t KWin/Script -i ~/tmp/test/package
Successfully installed /home/user/.local/share/kwin/scripts/test4/
$ kpackagetool6 -t KWin/Script -r test4
Successfully uninstalled /home/user/.local/share/kwin/scripts/test4/

The script is installed in ~/.local/share/kwin/scripts/${Id}

Thanks for your help!