9

Lets say I have three image files to edit. Consider all the files are in ~/Pictures. Let name of the first file be 1.svg, name of the second file be 2.svg and name of the third file be 3.svg .I have Inkscape editor. Now, I want a bash script to be executed so that the following must happen:

  1. First 1.svg must open for me to edit.
  2. After editing, when I close that file, automatically 2.svg must open for me to edit.
  3. Now when I complete editing 2.svg, I want 3.svg to open for editing.
  4. Now after editing 3.svg the script must end by closing GIMP.

PS:- If you are wondering if this is home work, it is not! See here . You will notice that I have to edit images there. To make that answer better I need help here. So please help. Also I AM A COMPLETE BEGINNER. I don't know anything about bash. So explain your answer as elaborately as possible. Also you might consider giving an answer with GIMP editor to edit .jpg files . It might be useful for others. By the way, I am using 14.04 LTS . Thanks in advance.

UPDATE :- The above linked answer was edited according to the accepted answer below.

Venkatesh
  • 2,351

4 Answers4

8

As Rmano says, you can simply do a for loop in the terminal:

for i in 1.jpg 2.jpg 3.jpg; do gimp $i; done

Either run this in the directory where the files are, or each file should have the rest of the path to it. You can put as many files as you want in there.

GIMP will open the file, you edit it, and then close GIMP. Once GIMP closes, the for loop continues and opens the next file in the list.

If you don't want to close GIMP every time, you can try adding a read -p:

for i in 1.jpg 2.jpg 3.jpg; do gimp $i && read -p "Press [Enter] key to continue..."; done

Once you finish editing a file, you should be able to press Enter in the terminal and the next file should open in GIMP, without having to close GIMP.

This is the simplest way I could think of, it may get complicated trying to detect when GIMP closes a file.

Note for your case

Most of the files are SVG files, as Rmano pointed out. So list all of your SVG files and replace gimp with inkscape. The PNG files will be fine with gimp.

Seth
  • 59,332
Nattgew
  • 2,139
7

The following command opens the files in the default associated application:

edit 1.svg 2.svg 3.svg

If you want to open all the .svg files in alphabetical order, you can use the * wildcard:

edit *.svg

* stands for any sequence of characters, so you can use it in other ways; for example, to successively open the .svg files whose name contains wibble:

edit *wibble*.svg

Other wildcards exist if you want to select files based on finer-grained patterns.

2

You could try something like this:

shopt -s nullglob
for i in *
do
    if [ -d "$i"  ]
     then
        continue
    else
        inkscape "$i"

    fi
done

I tested it on my Pictures directory and it seemed to work.

I don't entirely understand the first line yet, but it is there to help make sure my * works. The for loop then loops through everything in the current directory one at a time. If it isn't a directory it opens it in Inkscape for editing.

When you're done editing and close inkscape the next image will open until there are no more images.


For your specific case (after reading the linked question) this might work better. Remember to cd to /usr/share/unity/icons and then run this:

for i in file1.svg file2.svg file3.svg
do
    if [ -d "$i"  ]
     then
        continue
    else
        inkscape "$i"

    fi
done  

replacing file1.svg file2.svg file3.svg with a list of the files you want to edit.

terdon
  • 104,119
Seth
  • 59,332
0

Nomacs

https://github.com/nomacs/nomacs

If you are looking to go through some pictures in a directory and do some lightweight editing like rotate crop and color corrections, then Nomacs is a great fit.

Install on Ubuntu 24.04:

sudo apt install nomacs

Then when you open a directory with many images in it with:

nomacs .

you get thumbnails like this:

enter image description here

Double click on an image and it becomes big:

enter image description here

Then from there you can:

  • Shift-T: back to thumbnails
  • Left Right arrow keys: move to previous / next photo
  • C: crop with mouse. Once done:
    • Enter: apply the crop
    • Esc: abort the crop
    • Ctrl + Shift + S: save cropped image as a new file
    • Ctrl + S: overwrite original file
    • Ctrl + Z: undo edit
  • R: rotate
  • F2: rename

Here's what crop mode looks like for example:

enter image description here

Related: