[SOLVED] Nemo: size-dependent "open with"

Please post suggestions for improvement of Cinnamon here
https://github.com/linuxmint/Cinnamon
Post Reply
caetano
Level 2
Level 2
Posts: 67
Joined: Tue May 24, 2016 5:23 am

[SOLVED] Nemo: size-dependent "open with"

Post by caetano » Tue Oct 08, 2019 10:17 am

Is there a way (even a hack) to get a certain file type to automatically open with some application based on its size?
In my case I'd like to open images with one app when their size is below a certain threshold and with another app when it's above, just by double-clicking on the file in Nemo.
Last edited by caetano on Fri Oct 11, 2019 3:40 am, edited 1 time in total.

Hoser Rob
Level 15
Level 15
Posts: 5508
Joined: Sat Dec 15, 2012 8:57 am

Re: Nemo: size-dependent "open with"

Post by Hoser Rob » Tue Oct 08, 2019 10:59 am

I don't think that's possible. A search got me nothing, as I expected.

User avatar
smurphos
Level 12
Level 12
Posts: 4355
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Nemo: size-dependent "open with"

Post by smurphos » Tue Oct 08, 2019 11:09 am

It can probably be done via a custom Nemo action, basically an extra right click context menu entry. I will have a think/play and if I come up with something will post back.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

User avatar
smurphos
Level 12
Level 12
Posts: 4355
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Nemo: size-dependent "open with"

Post by smurphos » Tue Oct 08, 2019 4:04 pm

Question, for your images do you mean size as in file size e.g 100 MB or image resolution e.g 1080 X 1920?
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

User avatar
smurphos
Level 12
Level 12
Posts: 4355
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Nemo: size-dependent "open with"

Post by smurphos » Wed Oct 09, 2019 1:51 am

Assuming resolution based here is a sample nemo_action that as written will open images whose height and width is < 1080 in Image Viewer (xviewer) or height or width >=1080 in pix. It also requires imagemagick to be installed - apt install imagemagick - to get the image resolution.

This file should be saved as
~/.local/share/nemo/actions/open_image_with.nemo_action

Code: Select all

[Nemo Action]
Name=Open _Image With (Res. Dependent)
Comment=Opens small images with Image Viewer and larger images with Pix
Exec=<scripts/open_image_with.sh %F>
Selection=notnone
Mimetypes=image/bmp;image/jpeg;image/gif;image/png;image/tiff;image/x-bmp;image/x-ico;image/x-png;image/x-pcx;image/x-tga;image/xpm;image/svg+xml;
Icon-Name=image-x-generic-symbolic
Dependencies=xviewer;pix;identify;
Quote=double
It's associated script should be saved as and made executable
~/.local/share/nemo/actions/scripts/open_image_with.sh

Code: Select all

#!/bin/bash
for i in "$@"; do
if [ "$(identify -format %w "$i")" -ge "1080" ] || [ "$(identify -format %h "$i")" -ge "1080" ] ; then
  pix "$i" &
else
  xviewer "$i" &
fi
done
All being well when you right click on an image or a selection of images in Nemo, you'll have an extra context menu entry. Click and the image(s) will open in the specified app.

Image
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

caetano
Level 2
Level 2
Posts: 67
Joined: Tue May 24, 2016 5:23 am

Re: Nemo: size-dependent "open with"

Post by caetano » Wed Oct 09, 2019 12:05 pm

Thanks very much smurphos. This is very neat!
Either file size or image dimensions would've done it for me.
So I assume there's no way from there to make a double-click on the file execute that script (for the specified file formats)?

User avatar
smurphos
Level 12
Level 12
Posts: 4355
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Nemo: size-dependent "open with"

Post by smurphos » Wed Oct 09, 2019 1:51 pm

Hi, thinking about it it should be possible, by making a .desktop launcher for the script and making that .desktop file the default app for images.

I'm away from home and my Mint machine for a week or so, but if you haven't worked it out by the time I'm back I'll put something together for you.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

caetano
Level 2
Level 2
Posts: 67
Joined: Tue May 24, 2016 5:23 am

Re: Nemo: size-dependent "open with"

Post by caetano » Thu Oct 10, 2019 3:51 am

of course, silly me!
I went in an image's properties and changed the default "open with" to the shell script by browsing to it. Do you think there's a better way? (I'm on XFCE)

User avatar
smurphos
Level 12
Level 12
Posts: 4355
Joined: Fri Sep 05, 2014 12:18 am
Location: Britisher
Contact:

Re: Nemo: size-dependent "open with"

Post by smurphos » Thu Oct 10, 2019 4:59 am

If the GUI allows you directly set the script as the default application for an image file type then that should be fine.

I was thinking of Cinnamon where there is a GUI to set a preferred application for all image files types and I think it would need an extra .desktop file to appear in that GUI as an option. I can't recall if XFCE has an equivalent, but the way you've done it should be fine in any case.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.

Post Reply

Return to “Cinnamon”