Reply to topic

kwriteconfig create desktop icon

gulmet
Banned
Posts
10
Karma
0

kwriteconfig create desktop icon

Sat Nov 10, 2012 6:23 pm
What must I do to create desktop icons with kwriteconfig?
User avatar bcooksley
Administrator
Posts
18577
Karma
83
OS
I assume you are referring to *.desktop files? In any case, you need to write a file similar to this:
Code: Select all
[Desktop Entry]
Type=Application
Exec=krfb -caption "%c" %i
Icon=krfb
Categories=Qt;KDE;System;Network;RemoteAccess;


To do this, the following would be needed:
Code: Select all
kwriteconfig --file /path/to/file.desktop --group "Desktop Entry" --key "Type" "Application"
kwriteconfig --file /path/to/file.desktop --group "Desktop Entry" --key "Exec" "/path/to/binary <arguments>"
kwriteconfig --file /path/to/file.desktop --group "Desktop Entry" --key "Icon" "<icon name>"
kwriteconfig --file /path/to/file.desktop --group "Desktop Entry" --key "Categories" "Qt;KDE;Other;Categories;"


For icon names, you can run "kdialog --geticon apps" to get a dialog which will allow you to choose an icon. It will then print the name of that icon out to the console - that is what must be contained in the Icon key of a *.desktop file.

As for the Categories, this controls where it will be in the menu system. To appear in the network section for instance, one would set "Qt;KDE;Network;". Make sure to specify a trailing semi-colon to comply with the XDG specification.


System Settings and Device Actions KCM maintainer
Image
gulmet
Banned
Posts
10
Karma
0
bcooksley wrote:I assume you are referring to *.desktop files?


I refer too... See http://cdn.linuxforu.com/wp-content/upl ... esktop.png Mozila Firefox, Picasa, Google Earth are what I refer with desktop icons.

bcooksley wrote:To do this, the following would be needed:
Code: Select all
kwriteconfig --file /path/to/file.desktop --group "Desktop Entry" --key "Type" "Application"
kwriteconfig --file /path/to/file.desktop --group "Desktop Entry" --key "Exec" "/path/to/binary <arguments>"
kwriteconfig --file /path/to/file.desktop --group "Desktop Entry" --key "Icon" "<icon name>"
kwriteconfig --file /path/to/file.desktop --group "Desktop Entry" --key "Categories" "Qt;KDE;Other;Categories;"


For icon names, you can run "kdialog --geticon apps" to get a dialog which will allow you to choose an icon. It will then print the name of that icon out to the console - that is what must be contained in the Icon key of a *.desktop file.

As for the Categories, this controls where it will be in the menu system. To appear in the network section for instance, one would set "Qt;KDE;Network;". Make sure to specify a trailing semi-colon to comply with the XDG specification.

I tested this but no new icon on the desktop appears. Also not after reboot.
User avatar bcooksley
Administrator
Posts
18577
Karma
83
OS
If you open the created file with a text editor, what do you see?
Bear in mind, you do need to change the "<icon name>" in what I wrote to either the name of the application icon or the path to the application icon.
You can check the name of the icon using "kdialog --geticon apps".


System Settings and Device Actions KCM maintainer
Image
gulmet
Banned
Posts
10
Karma
0

Re: kwriteconfig create desktop icon

Sun Nov 25, 2012 11:58 am
How I create it:
Code: Select all
#!/bin/bash

test() {
kwriteconfig --file ~/.local/share/applications/test.desktop --group "Desktop Entry" --key "Type" "Application"
kwriteconfig --file ~/.local/share/applications/test.desktop --group "Desktop Entry" --key "Exec" 'krfb caption "%c" %i'
kwriteconfig --file ~/.local/share/applications/test.desktop --group "Desktop Entry" --key "Icon" "acrobat"
kwriteconfig --file ~/.local/share/applications/test.desktop --group "Desktop Entry" --key "Categories" "Qt;KDE;Other;Categories;System;"
# tested with and without the following two lines
kwriteconfig --file ~/.local/share/applications/test.desktop --group "Desktop Entry" --key "Name" "This is a Test"
kwriteconfig --file ~/.local/share/applications/test.desktop --group "Desktop Entry" --key "GenericName" "This is a Test"

kquitapp plasma-desktop
sleep 1
plasma-desktop
}

test


Resulting test.desktop file:
Code: Select all
[Desktop Entry]
Categories=Qt;KDE;Other;Categories;System;
Exec=krfb caption "%c" %i
GenericName=This is a Test
Icon=acrobat
Name=This is a Test
Type=Application


It appears in start menu. It does not appear on desktop.

I think we have to add something to the ~/.kde/share/config/plasma-desktop-appletsrc file? For test I manually added:

Code: Select all
[Containments][8][Applets][39][Configuration]
Url=file:///home/user/.local/share/applications/test.desktop


And it did work.

How can I do it with the kwriteconfig tool?
User avatar bcooksley
Administrator
Posts
18577
Karma
83
OS
It would not be recommended to use kwriteconfig to alter the Plasma configuration - as one would have to restart Plasma for it to take effect - if Plasma were not to overwrite your changes that is...

It would be recommended to use Plasma Javascript execution instead. Please refer to the documentation on KDE Techbase for information on how to do this. I will note that this is not necessary if you write your files to ~/Desktop instead and Plasma is configured to use a Folder View applet showing ~/Desktop.

You will still need to write the file under ~/.local/share/applications/ however to get it to show in the applications menu though.


System Settings and Device Actions KCM maintainer
Image
gulmet
Banned
Posts
10
Karma
0

Re: kwriteconfig create desktop icon

Mon Dec 03, 2012 10:20 pm
Yes, I made a symlink from ~/.local/share/applications/ (actually from my stacked kde settings folder) to ~/Desktop and activated folderview. Works great!
User avatar bcooksley
Administrator
Posts
18577
Karma
83
OS
Marked as solved, to make it easier for others to find later if they are looking for something similar.


System Settings and Device Actions KCM maintainer
Image

 
Reply to topic

Bookmarks



Who is online

Registered users: alake, Alexa [Bot], Baidu [Spider], Bing [Bot], Blingy, Deevad, edmael, einar, Exabot [Bot], garthecho, Google [Bot], google01103, GreatEmerald, haroldtejada, jfredrickson, koriun, lazyit, legnaVI, Majestic-12 [Bot], newtonnickel, parzt, pedrorodriguez, Tuukka, W3C [Validator], Yahoo [Bot]