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

kde service menu problem

Tags: None
(comma "," separated)
corsican
Registered Member
Posts
5
Karma
0
OS

kde service menu problem

Sat Apr 07, 2012 10:41 am
Hi, I am trying to make myself a service menu item replicating what I had in gnome2 nautilus actions. I have a script to join hjsplit files and delete the parts. (hjsplit is one of a number of programs that split a file into multiple pieces of a specified size and joins them back into one file also) i use lxsplit to do this in my script. each piece ends with an extension which is its number in the rejoin sequence, ie. .001, .002, .003 etc. obviously there is not a magic number associated, to get a mimetype as any type of file can be split and rejoined this way. nautilus actions allowed me to specify the type of file the context menu would appear on by either extension or mime-type, but it appears that kde only allows mime-types or "all files".
Is this just a corner case that means I'm out of luck? or does anybody know a way around it? tia
User avatar
carlosestensser
Registered Member
Posts
51
Karma
0
OS

Re: kde service menu problem

Sun Apr 08, 2012 12:54 am
Mind you: I am a complete newbie.
That said:
Can't you create a mimetype for files with extension 001 and assign that mimetype in the service menu?
corsican
Registered Member
Posts
5
Karma
0
OS

Re: kde service menu problem

Sun Apr 08, 2012 3:45 am
I looked into that option, and I may be wrong, but it appears that a mimetype is detected by the computer not by the extension, but by a "magic number" in the files header that is different for each file type. So you can have for example, an mpeg video file, delete the .mpg extension and the system will still detect it as an mpeg video file mimetype.

The file splitting programs don't change the original file in any way besides splitting them at defined boundaries and joining them back together, so we end up with say video.mpg.001, video.mpg.002 etc but also hugeimage.jpg.001 hugeimage.jpg.002 etc.

My script is designed to work only on the .001 files, but in these two cases video.mpg.001 would have a mimetype of video/mpeg and hugeimage.jpg.001 would have a mimetype of image/jpeg so I cannot set the menu to only be available on .001 files by detecting mimetype.

My script will refuse to do anything with non .001 files of course, but the service menu will come up for all files which is irritating, especially when it seems that the option to set by extension has been omitted because "modern operating systems shouldn't need to go by extensions"
User avatar
google01103
Manager
Posts
6668
Karma
25

Re: kde service menu problem

Sun Apr 08, 2012 10:41 am
possibly (say possibly because I have not actually done and tested it) create a new mime type using the file associations kcm in systemsettings

systemsettings -> add -> select group and provide name -> right click new mime -> general -> file name patterns -> add


OpenSuse Leap 42.1 x64, Plasma 5.x

corsican
Registered Member
Posts
5
Karma
0
OS

Re: kde service menu problem

Sun Apr 08, 2012 11:07 am
That was a great idea google01103, I thought you had it licked when I tried, it allowed me to add the mimetype based on the extension .001, but unfortunately dolphin still detects the mimetype of the original file and lists that instead, and the context menu will not appear when limited to my new mimetype.
User avatar
google01103
Manager
Posts
6668
Karma
25

Re: kde service menu problem  Topic is solved

Sun Apr 08, 2012 11:42 am
try running kbuildsycoca4 --noincremental and restarting kde

I guess the question would be happens when an extension is defined as being multiple mime types. For example .doc is defined as being both plain and msword mime types


-


OpenSuse Leap 42.1 x64, Plasma 5.x

corsican
Registered Member
Posts
5
Karma
0
OS

Re: kde service menu problem

Sun Apr 08, 2012 1:19 pm
That worked!
however it has exposed a new problem to me and I can't quite understand whats going on. This is the second service menu I have implemented, both run a bash script located in ~/username/bin
the first works on mpg files (or multiple mpg files) I exec it with %U and it does its work on the files and deposits the result in the directory that contains the file i right clicked on.

my second service menu that you just helped me with works on the .001 files but deposits the result in my home folder. I can't work out why...
nautilus-actions allowed to specify the working directory, service-menus doesnt seem to, but the first script works in the original file dir, while my other script sends stuff back to home!?!

any ideas?

btw thanks for the last solution
User avatar
google01103
Manager
Posts
6668
Karma
25

Re: kde service menu problem

Sun Apr 08, 2012 2:07 pm
maybe you should add something like :
Code: Select all
dir=$(dirname "$1")
cd "$dir"
to your script

You also might consider posting a new and more focused thread about placement of service menu scripting results

ps I borrowed the above code, an indication of my actual scripting abilities >:D


OpenSuse Leap 42.1 x64, Plasma 5.x

User avatar
google01103
Manager
Posts
6668
Karma
25

Re: kde service menu problem

Sun Apr 08, 2012 2:33 pm
Maybe your issue is that hsplit has an default output directory of ~/ and you need to provide an output dir if you don't want the default when calling it


OpenSuse Leap 42.1 x64, Plasma 5.x

corsican
Registered Member
Posts
5
Karma
0
OS

Re: kde service menu problem

Mon Apr 09, 2012 1:33 am
That worked, and I guess made the script more robust, still a bit strange, lxsplit claims to output in the current directory but obviously my script wasnt being executed in the current directory, whereas my ProjectX script was.
my projectX script didn't have a change to dir like your example in it, so I'm still a bit curious as to why one worked and not the other. I might dig around. thanks for all the help!


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft