This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Help with KDE Service Menu creation

Tags: None
(comma "," separated)
seniazi
Registered Member
Posts
3
Karma
0
OS

Help with KDE Service Menu creation

Fri Dec 20, 2013 9:39 am
Hello community,

I created a small KDE Service menu in order to use the export to pdf function of Libreoffice (I use libreoffice 4.1.4 installed in /opt from the debs provided by the Document Foundation web page. I use KDE4.8 on Debian Wheezy 64bit, but would want this to also work on OpenSuse 12.3 KDE 4.10 .
The Service Menu is the following:
Code: Select all
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=application/vnd.oasis.opendocument.text;application/msword;
Icon=acroread
Actions=convert2pdf;
TryExec=/opt/libreoffice4.1/program/soffice

[Desktop Action convert2pdf]
Name=export to pdf with Libreoffice 4.1
Name[el]=εξαγωγή σε pdf με Libreoffice 4.1
Name[de]=Als pdf exportieren mit Libreoffice 4.1
Icon=acroread
Exec=/opt/libreoffice4.1/program/soffice --headless --convert-to pdf "%f"


The service menu works fine. However, it exports the pdf to the ~/Documents folder irrespective of where the file I apply it on is located. On the contrary, if I run the same command on the command line
Code: Select all
/opt/libreoffice4.1/program/soffice --headless --convert-to pdf FILENAME.odt

the pdf is exported to the directory where the original is located. How could I change my Service Menu in order to also use the directory of the original file?

Thank you!
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Chances are Libreoffice is simply exporting the file into the "current working directory". The easiest way to fix this would be to use a wrapper script around it, which runs the following before executing Libreoffice. $1 in this case is the first argument to a shell script, which would be %f.
Code: Select all
cd `basename $1`


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
seniazi
Registered Member
Posts
3
Karma
0
OS
Hello Ben,

thank you for the answer.
Chances are Libreoffice is simply exporting the file into the "current working directory".

This seems to be true, as it is exactly what it does when executing the above command on the terminal.
I am not exactly sure I understood your answer though. My bash scripting skills are unfortunately rather limited.
I experimented with basename. As I understand it, it would return the filename and not the path, did I misread something?
I found however that dirname would provide the path. This:
Code: Select all
Exec=/opt/libreoffice4.1/program/soffice --headless --convert-to pdf "%u" --outdir $(dirname "%u")

seems to work.
Thank you!
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
Oops - I got my directives confused. Yes - dirname is what should be used in this case.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], lockheed