Tuesday, April 27, 2010

plasma shell scripting

It's been a ridiculously busy few weeks during which I haven't had much time to write and keep everyone up to speed on what's up and going on (let alone some of the other writing chores I have on my plate right now). Let's see if I can't get everyone caught up over the next few days though, starting with this blog entry.

Today I held a tutorial in #plasma on irc.freenode.net aimed primarily at KDE packagers about the Plasma Desktop Scripting framework. I felt this was an important topic to do some downstream communication on since it's become central to how plasma-desktop handles initial setup, updates and things like layout templates. While plasma-desktop has supported this feature since the 4.4 release, there are a lot of new features in 4.5, it's taken on a more central role and some of our downstreams managed to get things Very Wrong(tm) with their scripts in 4.4. So I was very happy to see that several distros were represented by those who turned out. I should also tip the hat to Jonathan Riddel for organizing the time and announcing it on the KDE Packagers mailing list.

Hopefully someone will post a cleaned-up version of the log from that session as it was very informative and lots of great questions were asked and answered. We'll see, I suppose. :)

There was also a feature request part of the tutorial right at the end. (See, this is why you want to attend when its announced on the mailing lists! ;) A total of nine additions to the API were requested, and all of them have been implemented in the hours following the meeting.

I look forward to seeing what our various downstreams will be able to do with this powerful new tool. There were some great ideas about how to address various management issues floated, such as how this opens up the possibility of handling Plasmoids that have a bug, but only in a specific version of them. It's really interesting to see the possibilities that open up when we give the power of a scripting language to people. :)

It's such a great tool, actually, that I spent some time last month extracting the scripting from plasma-desktop and putting it into libplasmagenericshell. This means that in 4.5 Plasma Netbook will also sport the same javascript API (though not the interactive console) and when the Plasma front end for KDM is completed it will support it as well.

7 comments:

chani said...

yeah but how the heck do you *open* that console?

Aaron J. Seigo said...

you open it by opening krunner and typing "desktop console" or from a konsole with "qdbus org.kde.plasma-desktop /MainApplication showInteractiveConsole"

documentation is here:

http://techbase.kde.org/KDE_System_Administration/PlasmaDesktopScripting

Tim Richardson said...

How can you script behaviour of existing panels? I want to resize the main desktop panel after enabling an external monitor. Are all existing panels exposed to a script somehow?

Aaron J. Seigo said...

@Tim Richardson: yes, and it's all explained on the techbase page i mentioned in my first comment there.

you can iterate over all panels with:

for (i in panelIds) { var panel = panelById(i) }

Tim Richardson said...

This is a little script I used to solve my requirement.


function listProperties(obj) {
var propList = "";
for(var propName in obj) {
if(typeof(obj[propName]) != "undefined") {
propList += (propName + ", ");
}
}
print(propList);
}

p = panelById(panelIds[0]);
if (typeof p === "undefined") {
print("E: Couldn't find first panel");
exit();
}


p.length = screenGeometry(p.screen).height;

Tim Richardson said...

How do I run a script from a shell, but not interactively?

herbiehancock said...

@Tim Richardson
Here is a workaround for running a script from a shell automatically:
http://sidux.com/index.php?name=PNphpBB2&file=viewtopic&p=157373&sid=e8565943e21fdee9dd2c27a6fd0e7c96#157373