Executive Summary
To cut to the chase, if you want to save your current sessions in KDE4 run the following command from a command line ( or put it in a script that you can call from a desktop shortcut ):
dbus-send --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.saveCurrentSession
The Details
Now for how I got here in the first place:
I’ve just upgraded to Kubuntu Hardy Heron and decided to give KDE4 a go. I’ll be posting about the upgrade process and KDE4 in general over the coming days but one thing that has kept me “amused” today is the lack of a “Save Current Session” button in KDE4
Rather than have the desktop returned to how it was when I last logged out ( “Restore Previous Session” under KControl ) I like to return to a standard set of applications so I use the “Restore Manually Saved Session” option under KDE 3.5.
In KDE4 KControl there are the same options for the session manager. The snag is that there is no button anywhere to actually save the session when you want to. Thus choosing this option effectively logs you back in to a blank session. This has been reported as a bug in KDE but does not seem to be making any progress.
Flushed with my success with dcop recently I was hoping I could use it with the ksmserver object ( the session manager ) but in KDE4 dcop is not used and the dbus interface is used instead which is a bit more complicated to use.
There is a tool you can install called kdbus that does a similar job to kdcop but I found a much better tool called qdbusviewer along with a useful overview of KDE and dbus here.
To use qdbusviewer you need to install the package qt4-dev-tools then run qdbusviewer from a command line:-
sudo apt-get install qt4-dev-tools
qdbusviewer
You can use qdbusviewer to browser what objects are available and execute methods on them just like kdcop and kdbus ( but kdbus is rather slower )
Thanks Simon. I’d noticed that “save current session” had either dissapeared or moved to somewhere beyond my knowledge in recent KDE 3s in Kubuntu. Thanks for the tip on doing this in 4! (Building today’s KDE 4 SVN as we speak…)
Hi Pete,
I haven’t seen that issue with the 3.5 builds, certainly Hardy Heron 3.5.9 has a save session button on the kicker as long as you have “Restore Manually Saved” session switched on in the Session Manager.
However in KDE 3.5 the dcop equivalent is:-
dcop ksmserver default saveCurrentSession
Hi, Reatsel!
Thank you for your useful suggestion on using dbus-send. In my case (Kubuntu 8.04, KDE4) however it didn’t work. I checked with kdbus and found the command line that worked:
dbus-send –session —dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.saveCurrentSession
This allowed me to save the session I needed, though this session included terminal I used to run the commanу itself. When I tried to use ‘run command’ on KDE desktop it didn’t work.
Is there a workaround?
Thanks and regards
Hi Resu,
I managed to get a desktop shortcut to work. I created it with the following executable command:-
/usr/bin/dbus-send –print-reply –session –dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.saveCurrentSession >/tmp/session.out 2>&1
Not that when this is clicked it creates a file call /tmp/session.out that you can look at to see the output of the command. Also I have added the –print-reply option which will show the response from the dbus server. Which should be something like:-
method return sender=:1.6 -> dest=:1.49 reply_serial=2
Oh and please note that the command line options all need double dashes before them i.e. – – , wordpress is mangling these to show a single long dash
--Hi!
Nice article! I’m trying to grow from it to custom my acpi power button event to ask user to shutdown when button pressed. But I can’t handle the fact that root can’t send message to other users.I’m using
#usr/bin/dbus-send –session –type=method_call –dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout int32:1 int32:2 int32:0
this works fine when called from the user logged in, but not from root.
Do you know how to handle this situation?
Thanks.
Hi Edney,
I haven’t really done anything with passing parameters to dbus-send etc. but a couple of things spring to mind.
Firstly would using the system bus work rather than the session bus :-
dbus-send --system --type etc etc.Or failing that can you find out the name of the user logged in and use the su -c command as root to send the info as that user? (Not ideal but might work):-
LOGUSER=[ some code to work out the user ]
su - $LOGUSER -c dbus-send --system --type etc etc
Here you can find out how to suspend or the system as well:
http://linux-tipps.blogspot.com/2008/08/standbysuspend-to-ram-with-dbus-in-kde.html
I found I can tell KDE4 to launch certain programs at the start of each session with the new “Autostart” system settings module. (I set the Sessions module to “start with an empty session”.) It’s a little more work, because you have to add an entry for each program, but since there’s no “Save Session” button, it’s probably easier at this point.
The autostart tool could be a good replacement of the “Restore-Saved-Session” way – but it seems that autostarted applications currently can’t be bound to a specific “desktop” of the pager.
Hi,
I stumbled upon your blog entry while trying to figure out how to save the KDE4 session. Now (KDE 4.3) they “solved” the bug, but to me it was still very unclear how to save the damned session.
http://bugs.kde.org/show_bug.cgi?id=182662
The option is “hidden” in the kickoff menu in the “LEAVE” tab. However, in lancelot (http://lancelot.fomentgroup.org/main) – that I’m using – the option is not displayed. Also, I am a bit disappointed that this option is not displayed in the Session Management window… but still.
Bye.
Pingback: 2010 in review « Harsh but fair
Yes, this can be scripted, but is also available in the GUI in KDE 4.x in Ububtu 10.10.
Here are the steps to find it, if it is lost:
1) Click on the blue KDE-Start button usually at the left end of your kwin panel
2) Type “session” in the top search box, ‘session management’ will appear.
3) Click session management – it will give a config dialog
4) in the config dialog select: On Login: Restore manually saved session
5) Click ‘Apply’, ‘OK’
Now whenever you navigate to the ‘Leave’ tab in the KDE start menu
you will see the missing option ‘Save session: save current session for next login.
HTH
Pingback: Share bookmarks