I want code to right click context menu on a file and if it is a .mp4, then convert that to a .mp3 of the same name
also include an option to play faster by +25 +33 +50 or slower by -25 -33 -50 (in a sub menu)
I understand this is different depending on your system, so answer how to do it for the people who use the same system as you
You got me curious, so I looked it up.
This isn’t a “let me google that for you”, it’s an “I’m joining you on this journey”.https://develop.kde.org/docs/apps/dolphin/service-menus/
(KDE)Looks like you drop a .desktop file into ~/.local/share/kio/servicemenus.
Name the file extensions, write your Exec= line, fill in a couple other details like what icon to use and what it should be called in the right-click menu, save it, and you’re done.
I imagine it’s similar in xfce.Looks like Thunar has a “Custom Actions” feature under the Edit menu where you can get the same result.
Can I just say something? I personally view (almost) anything that involves editing configuration files by hand as an opportunity for the Linux community to implement a GUI.
You’re absolutely right, I’m surprised that xfce (or Thunar anyway) has a GUI for it and KDE doesn’t.
KDE might and I just didn’t find it in the search results.Pull request time!
I still haven’t had to edit any files for this task, I was able to install packages and check boxes in a gui to add menu items ( kde / dolphin )
Thanks for volunteering yourself and your own time to this endeavor.
So you admit the lack of GUIs on Linux is due to a lack of developers?
You don’t think it’s easier for users to edit configuration files by hand?
Well, more choice is a good thing. So long as the configuration file stays available as well (because it makes it way easier to script this configuration), then having a GUI available is cool, too.
Having said that, the particular feature that OP wants is for people who want to script things, meaning most of them will prefer the configuration file anyways. You’d need quite a lot of spare devs for one of them to get bored enough to want to develop a GUI, which will not see much usage.
Actually no I don’t.
Linux doesn’t lack GUIs; there’s at least ten entire Desktop Environments in active development at any given time and several of them are quite feature complete such as Cinnamon and KDE. Then you’ve got GNOME which is polished if deliberately feature poor.
A few DEs do have GUI applets for editing the context menu but not all do. Windows doesn’t have one built in. Quote the second page of that thread:
Id prefer NOT to use a third party app to make it work. I just wish Microsoft would just make is fully Customizable for us all.
I’m a subscriber to the old adage “GUIs make simple tasks easy, CLIs make complex tasks possible.” This task is either within the city limits of shell scripting or close enough to read the “Speed limit 35 unless posted” sign, so it might as well be left as a “write a config file” type thing.
Editing a config file takes a few seconds. Implementing a GUI takes hours of unpaid labor, and depending on the case the UX in the end might be almost identical.
The UX at the end should never be identical.
It’s why laypeople shy away from Linux. They prefer GUIs because GUIs are easier for users.
Well, sometimes it’s gonna be. What if there’s a field that can take an arbitrary string? You would rather input that string into a styled form input with some buttons to click than use a text editor for a second?
Absolutely!
How am I supposed to know where to find the file? Editing files by hand is also more error-prone compared to using a GUI. It’s not for laypeople and they shouldn’t have to adjust for it.
A big appeal of software development for me is making things easier for users even if it’s harder for the developers to implement. That’s good design, and great work.
Okay if finding the file is the problem I assume you’re just allergic to documentation, which, yeah, would make configuring things pretty annoying.
Hypothetically yes it would be great if all settings were easily discoverable and all users could easily make all their software work exactly how they want. In practice you’re asking for a huge amount of development by unpaid volunteers whose time could be (and is) going to, for example, the actual features or configuration options that you’re trying to set in the first place.
Most apps with GUIs do expose most settings that “laypeople” would use, anyway. OP is literally asking to be able to run custom scripts from context menus, I’d love to see your suggestion for implementing a clean and user-friendly GUI for that.
Allergic to documentation? See, this is where the free software community fucks up. Stop putting the onus of usability on the users. It’s the role of developers to make their software easy to use for people who aren’t working on it. That’s why macOS and Windows are still dominant to this day. The companies that develop them realized decades ago that laypeople don’t want to and shouldn’t have to read documentation or sift through configuration files if software can be designed so that it’s easier to use.
Unfortunately, thanks to people like you, getting this solution across to the Linux community at large is like pulling teeth.
I’d be happier if we could just admit, “Yeah, GUIs are better but they’re harder to implement so we don’t do it.” At least then we’re being honest and not trying to blame users for the lack of developers.
As it stands right now, your rhetoric actively discourages people to take up GUI development because you keep trying to make it a user problem, not a developer one.
In the Cinnamon desktop, there’s a directory in ~/.local/share/nemo/actions. Navigate to this directory in Nemo file manager and a message will appear across the top, it has a built-in tutorial as to how to do this. You create a short config file with a .nemo_action that defines what an action does, what context it appears in, what text it displays, what icon it displays etc. and the command to run when chosen.
It’s been about a year since I’ve messed with this, but IIRC if it’s set up to fire with one or more files selected, it will pass the file names to the command as arguments. You can configure it to run on exactly one, one or many, or specifically plural files. A thing I did a lot was allow it to take multiple files and then iterate across the variables in a for loop, so say I used pandoc to convert .docx files to .pdf, I could highlight 50 of them, click one option and it would churn through all of them.
I’m not going to build the script for you, but the first approach that occurs to me would be to write a shell script that calls ffmpeg to do the conversion, get that to where it works when you invoke it from the terminal, then write a .nemo_action file to fire it from the GUI.
As for the playback speeds…I’m not sure how to get that done. If you mean “take this .mp4 and make an .mp3 out of its audio that is 25% faster” I think what would happen there is you’d write a little GUI pop-up window, I would do it in Python with either a GTK or QT module, that would open up to ask parameters before passing that back to the main script to do the work.
Wow thanks I will try this cinnamon destop
Good luck! Hope it does what you want it to!
some desktop environments and window managers have built in functionality to do this through something like config files or a gui config.
the intentionally “simplified” or “streamlined” alternatives (ie gnome) requires more involvement and runs at a gradient between simple kde like config file at one extreme end, to full on source modification at the other extreme end.
if something like this was a common thing for me; i would go with an environment that makes the bells and whistles available to you as the default option, like kde.
I’ve often said the perfect GNOME utility applet is a blank window titled “Gnothing” with a button in the top bar that says “never mind”, while the ideal KDE utility applet is the instrument panel of an Apollo CSM crashed at an oblique angle into the Chernobyl control room labeled “text viewer.” And Cinnamon usually sits somewhere between those two extremes.
Even if a file manager doesn’t have this feature, you can probably get around that by adding a new .desktop file in ~/.local/share/applications that accepts specific MIME type and runs a script on “opened” files.
that’s the beautiful thing about linux; so many way to accomplish a goal and it you can do it at any experience level.
the best part is that all of it is free and your solution is easily shareable through things like social media and source code repositories where people with more experience can improve upon your idea further. if your idea is REALLY good, it will become mainstream.
Step 1) Install a file manager…
Are you using GNOME or KDE? I know those can definitely utilize shell scripts from the right click menu. I’d recommend grabbing FFMPEG (probably already have it) and SOX. You are going to need to create a pretty basic shell script that extract the audio as a wav using FFMPEG, changing the speed with SOX (you can use FFMPEG but I find the audio warping dog shit), then FFMPEG to convert to mp3. For both GNOME and KDE the context menu shortcuts typically only pass the path to file you have selected as an argument. So you’ll need to create a script for each speed. Honestly, it’s not gonna be easy. You might find something in the Dolphin (kde filemanager) settings that will enable some basic context menu scripts for converting video to mp3. If this is too intimidating then I would check github for an FFMPEG wrapper. It’s the a/v swiss army knife in linux.
Which file browser are you using?