Opening from Nautilus behaves different than from the terminal

Hi everyone. Almost 10 years Linux user, can’t believe it’s the first time I talk in a Gnome forum. I swear I haven’t been avoiding you. I guess your software is too perfect :wink:

Anywho, in the terminal, if I do:
gthumb ./image1.jpg ./image2.jpg
gThumb opens a single window containing a gallery of the chosen images.

However, if I put gthumb $@ in a script and assign this script as the default program to open images, then select images in Nautilus and hit enter, gThumb opens each image in an individual window.

How can I make it behave the same as in the terminal ?

If you must know why I want to put this in a script:
As you may or may not know, gThumb can’t properly display images above 2^15px in width or height (a limitation of the cairo package).
So I’m making a script to have Nautilus open images with another program (Firefox) whenever that size is reached.

What did you put in the Exec key in the .desktop file you used when adding your script as a default program? If you used %f or %u that means your script can only handle a single file/URI and multiple instances will be launched. If you use %F or %U instead, that means it can handle multiple files/URIs and only a single instance should be used.

There is no desktop file. To my knowledge desktop files are meant either for menu entries or application shortcuts. This is neither of those. The script should run when double-clicking an image or hitting enter on multiple images.

Just to be sure, I tried creating a desktop file like this:

[Desktop Entry]
Name=open with gThumb
Exec=gthumb %F

and set it as default program for images but nothing happens when I double-clic an image.
(I tried with %f, %U and %u too)

There is no desktop file.

How did you assign your script as default handler for images without a .desktop file?

Right click on image > Properties > Open with > select the script

For the script to show up in that dialog there has to be a .desktop file for it. That’s the one you need to modify. It’s probably somewhere in ~/.local/share/applications.

Ok, I just noticed that Nautilus doesn’t have the browsing button. Nemo added it, and looking in that folder you mentioned I could see that Nemo automatically created a desktop file for it. I was unaware of that.

And now I think I understand why the desktop file I created didn’t work.
I located this .desktop file wherever, then right-clicked on an image>Properties>Open with and selected the desktop file, so what happened was Nemo generated a desktop file out of another desktop file, and that can’t work.

So back to the issue at hand, I edited the proper generated desktop file, replaced the whole exec command by simply gthumb %F and gThumb now opens the images all at once!
Now to make the script work with it…

And it works!
This is the content of my script:

for img in "$@"; do
  if [[ "$(identify -format %w "$img")" -gt 32767 ]] || [[ "$(identify -format %h "$img")" -gt 32767 ]] ; then # 32768 (2^15) is the limit gthumb can handle
if [[ $app == 1 ]]; then
  gthumb "$@" &
elif [[ $app == 2 ]]; then
  firefox "$@" &

And this is the content of the .desktop file:

[Desktop Entry]
Exec=/path/to/my/script %F
Name=My script

Thank you @skeller!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.