21

As well as being a Panda I am also an artist, I make my artwork mostly in GIMP and save my pictures to a certain directory on my computer. However I have a slight inconvenience because I save my images in jpeg format, however the default program to open jpegs is the Image Viewer, and if I change it to GIMP for convenience with my artwork, it means that all the other jpegs on my computer open in GIMP, and I don't want them to so this is where the problem begins...

So I am wondering if there is any way to make it so that all jpegs opened in that certain directory on my computer open in GIMP, but all other jpegs elsewhere open in the Image Viewer?

  • Only for Nautilus/Files or also for xdg-open? – A.B. Dec 28 '15 at 12:43
  • @A.B.: I would say both if that can be done. – user364819 Dec 28 '15 at 12:50
  • For xdg-open in a terminal you'd have to change the mimetype of your images. – A.B. Dec 28 '15 at 13:24
  • Or you could also use the script in my answer with the complete image path. – A.B. Dec 28 '15 at 13:24
  • 4
    Never use .jpeg as an intermediate format! It incurs generation loss. Why don't you just save the images as .xcf, which is always automatically opened with GIMP? – leftaroundabout Dec 28 '15 at 15:46
21

You need a desktop file, and a wrapper script:

  1. The desktop file

    • Create a desktop file

      nano ~/.local/share/applications/jpeg-wrapper.desktop
      
    • Add the configuration below (change the property for Name)

      [Desktop Entry]
      Name=Special or Standard
      Comment=Open a JPEG depending of the path
      Exec=/home/user/bin/jpeg-wrapper %f
      Icon=
      Terminal=false
      Type=Application
      Categories=Editor;
      StartupNotify=true
      MimeType=image/jpeg;
      
    • Replace user in Exec=/home/user/bin/jpeg-wrapper %f with your username, the output of

      echo $USER
      
    • Replace the icon name in Icon= with a name or path of your choice

    • Use MimeType=image/jpeg to specify the mime types of files for which the decision is to apply. Separate multiple mime types via ;

      Get the mime type via

      mimetype your_file
      

      e.g. for a text file

      text/plain
      
  2. The wrapper script

    • Create a new script

      mkdir -p ~/bin
      nano ~/bin/jpeg-wrapper
      
    • Add the code below

      #!/usr/bin/env bash
      image_path=$(dirname "$1")
      my_special_path="$HOME/tmp"
      open_with_special="gimp"
      open_with_standard="eog"
      
      if [[ $(mimetype -b "$1") == "image/jpeg" ]] && [[ "$image_path" == "$my_special_path"* ]]; then
              "$open_with_special" "$1"
      else
              "$open_with_standard" "$1"
      fi
      
    • Change my_special_path to your artwork folder. All subfolders are also considered.

    • Change open_with_special to your special application (e.g. gimp)

    • Make your wrapper script executable

      chmod +x ~/bin/jpeg-wrapper
      
  3. Restart Unity/GNOME Shell, for the GNOME Shell e.g. Alt-F2, type r and Enter

  4. Associate one or more file types with the desktop file

    • Open your file manager and right click on a file for which the decision is to apply

    • Click Properties

    • Activate the tab Open With

    • Select the entry Special or Standard

    • Click Set as default

  5. Enjoy ;)

Script checked here.

|improve this answer|||||
  • Does it matter what I change the Name value to? – user364819 Dec 28 '15 at 17:09
  • No, change the name as you would like. – A.B. Dec 28 '15 at 17:11
  • Also, your script has a slight problem... Uhm... All the files in my artwork folder now open fine in GIMP, and the same for all subdirectories, however if a file is not in that area, it just does not open at all. – user364819 Dec 28 '15 at 17:19
  • Let me check it. – A.B. Dec 28 '15 at 17:20
  • Ok, it works fine now that you removed the infinite loop. ;) – user364819 Dec 28 '15 at 17:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy