Hi, I am trying to write a simple macro using kwinscript but there’s no log output.
This is my script:
let sessionHandle = null;
function initializeRemoteDesktopSession() {
callDBus(
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.RemoteDesktop",
"CreateSession",
{ "handle_token": "session_token" },
function (reply) {
if (reply.error) {
console.log("Failed to create RemoteDesktop session:", reply.error);
return;
}
sessionHandle = reply["session_handle"];
console.log("RemoteDesktop session initialized:", sessionHandle);
// Request screen cast permissions with keyboard access
callDBus(
"org.freedesktop.portal.Desktop",
sessionHandle,
"org.freedesktop.portal.RemoteDesktop",
"Start",
{ "devices": 2 }, // 2 = Keyboard device
function (startReply) {
if (startReply.error) {
console.log("Failed to start RemoteDesktop session:", startReply.error);
} else {
console.log("RemoteDesktop session started successfully.");
}
}
);
}
);
}
function sendKeyEvent() {
if (!sessionHandle) {
console.log("No active RemoteDesktop session. Initializing...");
initializeRemoteDesktopSession();
return;
}
let device_id = 0; // Use device ID 0
let keycode = 48; // B key (evdev keycode)
// Send key press
callDBus(
"org.freedesktop.portal.Desktop",
sessionHandle, // Use session handle as path
"org.freedesktop.portal.RemoteDesktop",
"NotifyKeyboardKeycode",
[device_id, keycode, 1], // Press event
function (reply) {
if (reply.error) {
console.log("Failed to send key press event:", reply.error);
} else {
console.log("B key pressed.");
// Send key release after a short delay
setTimeout(() => {
callDBus(
"org.freedesktop.portal.Desktop",
sessionHandle,
"org.freedesktop.portal.RemoteDesktop",
"NotifyKeyboardKeycode",
[device_id, keycode, 0], // Release event
function (releaseReply) {
if (releaseReply.error) {
console.log("Failed to send key release event:", releaseReply.error);
} else {
console.log("B key released.");
}
}
);
}, 50); // 50ms delay to simulate a quick press
}
}
);
}
registerShortcut(
"Remap A to B",
"Remap A to B",
"A",
sendKeyEvent
);
initializeRemoteDesktopSession();
The script first use registerShortcut
to bind to a
. Then the script uses RemoteDesktop
XDG Desktop Portal to send inputs in a secure way. In this case, it’s sending the b
key. So this script sends the input b
when a
is pressed.
There’s a bug in my script and I can’t debug because there’s nothing in the console. The output from plasma-interactiveconsole --kwin
just says that the script is loaded and nothing else.
I found this issue using journalctl
. It uses the command journalctl -g "js:" -f
it also doesn’t work as it also display if the script is loaded or not.
Is there another way to check the logs of a kwinscript? And also is there a way to turn off a kwinscript? It gets really annoying when there’s a bug in my script but the a
key is binded which doesn’t press a
.