Menu

#77 Command-line use

v1.0 (example)
open
nobody
None
5
2015-03-03
2015-02-27
Philipp
No

I want to call gimp on the command-line, like
gimp -i -b '(batch-generate-optimum-palette "120.png" 0 0 256 TRUE TRUE "")' -b '(gimp-quit 0)'

Before, I did ln -s /Applications/GIMP.app/Contents/MacOS/Gimp /usr/local/bin/gimp

Problem 1 was that the scipt GIMP.app/Contents/MacOS/Gimp cannot determine the current path, so I modified it to do

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
dirn="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

instead of line 6.

That seems to work, but then Gimp says:

2015-02-27 19:08:24.209 gimp-2.8[29642:3748776] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.

(gimp-2.8:29642): Gtk-CRITICAL **: gtk_box_pack: assertion 'child->parent == NULL' failed

Is this a known problem on OSX ?

(Yosemite, btw.)

Discussion

  • Philipp

    Philipp - 2015-02-27

    PS. (suggestion): Would it be possible to auto-create the softlink the first time Gimp is run, so that users can use the command-line without manually creating the link?

     
  • Simone Karin Lehmann

    well, I did all this work to get GIMP up to run as a gui application. I know that on Linux it's possible to run GIMP in batch mode from the console but on OS X, most users aren't used to the command line.

    And, from a technical point of view, the original GIMP sources make use of parsing the command line in its own way. But OS X applications use some system wide functionalities (Apple Events) to open files and read command lines. I've ported my build to use these native functions. This gave me the chance to implement such things as drag & drop from Finder, Dock icons, and others very easily.

    If you really need to use GIMP from the command line, change the last line of the script /Applications/Gimp.app/Contents/MacOS/GIMP to

    exec "$bundle_contents/MacOS/gimp-2.8" $*

    and use the script from the command line. But be aware, that now GIMP will open an image twice if you use the script without the "-b" (batch) option. Some other errors might occur too.

    BTW, the GTk-critical message can be ignored. It's a know issue to me (I've applied a hack to get ALT + window number working ...)

     

    Last edit: Simone Karin Lehmann 2015-02-27
  • Philipp

    Philipp - 2015-03-03

    Hi Simone, thank you for your very quick reply, and of course for your great work integrating Gimp with OSX (I was not aware of the level of integration, which would probably suggest to use automator).

    I am working together with people using Linux, and we use the shell script with Gimp commands for a certain workflow that I was glad we can share on Linux and OSX. Thats why I prefer the command-line.

    Thank you for your suggestion regarding the last line - it seems to almost work, but now gimp does not quit after the commands - Gimp says "batch command executed successfully" twice and then nothing happens, files are untouched. Are you aware of this problem? (Or do you think it is not OSX-related?)

    Thank you for your patience,
    and greetings from Vienna
    Philipp

     

Log in to post a comment.