Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 617  / 2 Years ago, sat, june 11, 2022, 6:34:05

I'm looking to create a file manager script to use in Caja (I used "Nautilus Script" in the title so people would understand what I was trying to accomplish) that will extract the selected archive (or multiple archives) to the current location. Preferably I'd like to specify Engrampa to do the extracting, but File-Roller, or even a command, would be fine (though I'd prefer to have the progress dialog pop up like when I extract them via "Extract Here").


Now, you may be wondering why I want a script for this when Caja has the "Extract Here" option in the context menu, just like Nautilus. The reason is that I've had great success assigning keyboard shortcuts to the scripts I use in Caja, so my objective is to be able to extract the selected archive(s) with a key-combo like Alt+X.


I have very limited expertise in scripts, but have managed to do some basic, but very useful, things like the following, which is open the selected image in Gimp, which I've assigned the combo Alt+I to:


#!/bin/bash
if mimetype -b "$1" | grep image; then
gimp "$1"
fi

I've used that same approach for a couple of other things that work great, like opening a folder with an image viewer, but trying to create a script for extracting the selected archive (specifically RAR, as that is what I most download) with Engrampa (engrampa -h) to the current folder, or even just the Unrar command (unrar e), nothing happens. I think the mimetype is specified correctly, I've tried it with engrampa minus the -h option to see if Engrampa pops up (all my working scripts have no option after the command), yet nothing happens at all. So, obviously I am doing something wrong with the script below:


#!/bin/bash
if mimetype -b "$1" | grep application/x-rar-compressed; then
engrampa -h "$1"
fi

So I am calling on your expertise to solve this. While it's not crucial, as I can do it with a right-click, it would be great to get this happening, so I can assign a key-combo to it. I'd be happy with a script just for use with RAR files, though one that will extract any type of archive would of course be most welcome. And while I'd prefer a GUI app to do this, so I can see the progress, it's not vital. Many thanks in advance, and stay safe everybody!


PS: I am using Ubuntu 20.04, in case that matters. And I switched to Caja a week ago, as the Nautilus devs keep removing functionality.


More From » scripts

 Answers
5

Many thanks to Michal for pointing me in the right direction with the Caja variable! At first this didn't seem to work, then I removed the line:


if mimetype -b "$1" | grep application/x-rar-compressed; then

... and it worked as expected, with a visual progress indicator, and it can unpack multiple selected archives. So the script code is:


#!/bin/bash
engrampa -h $CAJA_SCRIPT_SELECTED_FILE_PATHS
fi

I've set Alt+X (for eXtract) as the shortcut/accelerator, and all is perfect!




UPDATE: I did come across one anomaly, being that when trying to extract an archive that contains a folder instead of files, it would throw up an "Archive type not supported" error message, and hence would not extract the archive (and I did try this on multiple archives that contained folders). However, after a while it came good (mostly - see below), so while I don't understand the how and why of those archives being treated differently to those containing individual files, and how that rectified itself, I'm not complaining!


(Edit: I've come across a couple of RAR archives containing a folder that still fail, and they are not corrupt or anything - they extract fine via right-click > Extract Here - so while that's still perplexing, and a tad annoying, I can live with having to do it that way for the occasional archive).


So I thought I'd share that info for anyone else who wants to use that script, which works for archives of any format (that is supported by Engrampa), for multiple selected archives, and also multi-part archives.


[#1013] Sunday, June 12, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tudatchful

Total Points: 270
Total Questions: 109
Total Answers: 122

Location: Palau
Member since Tue, May 30, 2023
12 Months ago
tudatchful questions
;