RSS/Atom feed Twitter
Site is read-only, email is disabled

run script located in an arbitrary directory

This discussion is connected to the gimp-user-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

7 of 7 messages available
Toggle history

Please log in to manage your subscriptions.

run script located in an arbitrary directory Robert Kleemann 21 Nov 21:44
  run script located in an arbitrary directory michael chang 22 Nov 01:17
   run script located in an arbitrary directory Robert Kleemann 22 Nov 02:33
    run script located in an arbitrary directory Manish Singh 23 Nov 10:38
     run script located in an arbitrary directory Robert Kleemann 26 Nov 20:52
      run script located in an arbitrary directory Carol Spears 26 Nov 23:18
  run script located in an arbitrary directory Carol Spears 22 Nov 01:40
Robert Kleemann
2005-11-21 21:44:38 UTC (over 18 years ago)

run script located in an arbitrary directory

Is it possible to have gimp run a script that located in an arbitrary directory? It seems that gimp wants to run scripts from ~/.gimp-n.n/[plug-ins|scripts]/

I often use gimp scripts to non-interactively create many images based on a few parameters. In these cases I use gimp as if it were a compiler e.g.
gimp scripts ==> source code
gimp ==> compiler
images ==> object files

Sometimes I even use a makefile run gimp and check all the source files into a source control project.

Given this way of using gimp, it would be very handy if I could run gimp in some way so that it would run a specified script that is not located in one of the standard gimp directories. I have found that it is possible to specify the entire script on the command line via:

gimp -i -b "$(cat script.scm)"

But this has a couple problems: 1) All of the code exists on the same "line" so if there is a syntax error it is very difficult to track down 2) It only works for scripting languages where white space is not significant. This means you can't use this with python-fu (my preferred scripting language)

Am I missing something? Is there an obvious way to do this?

If there is no way to do this, would it make a good feature request?

Robert.

michael chang
2005-11-22 01:17:51 UTC (over 18 years ago)

run script located in an arbitrary directory

On 11/21/05, Robert Kleemann wrote:

Is it possible to have gimp run a script that located in an arbitrary directory? It seems that gimp wants to run scripts from ~/.gimp-n.n/[plug-ins|scripts]/

2) It only works for scripting languages where white space is not significant. This means you can't use this with python-fu (my preferred scripting language)

Am I missing something? Is there an obvious way to do this?

While Perl-fu is not ... at it's peak at the moment, from my memory, perl scripts with the GIMP module can be loaded just like any executable script; for example, if I have a script that uses GIMP called myfile.pl and I go to that directory and call ./myfile.pl, it will run. [In fact, this is the only way I've figured out how to run them -- I still haven't figured out how to register a Perl-Fu script in the menus. Heh.] I don't know about Python, but I can imagine it could be possible - although would you need to open the images from Python itself to do so?

If there is no way to do this, would it make a good feature request?

*IF* there is no way to do this, I myself don't see anything wrong with the idea... the only thing is I don't know when/if it'd be completed.

--
~Mike
- Just my two cents
- No man is an island, and no man is unable.

Carol Spears
2005-11-22 01:40:40 UTC (over 18 years ago)

run script located in an arbitrary directory

On Mon, Nov 21, 2005 at 12:44:38PM -0800, Robert Kleemann wrote:

Is it possible to have gimp run a script that located in an arbitrary directory? It seems that gimp wants to run scripts from ~/.gimp-n.n/[plug-ins|scripts]/

File-->Preferences
there is an expander twisty for folders. from there, you can tell gimp to use "Plug-Ins" from other directories, effectively putting that directory into gimps path. this works for python and perl scripts and your compiled c plug-ins. the "Scripts" dialog would be the way to show it to other script-fu containing directories.

Given this way of using gimp, it would be very handy if I could run gimp in some way so that it would run a specified script that is not located in one of the standard gimp directories.

my preferences solution alone will not do this. running "gimp --gimprc " combined with setting the preferences differently there would do what you need, however. i have not tried all of this myself, it is just the approach i would take if i needed to do this.

please let us know if this works for what you are trying to do.

carol

Robert Kleemann
2005-11-22 02:33:22 UTC (over 18 years ago)

run script located in an arbitrary directory

michael chang wrote:

perl scripts with the GIMP module can be loaded just like any executable script; for example, if I have a script that uses GIMP called myfile.pl and I go to that directory and call ./myfile.pl, it will run.

Thanks for the idea. I never thought of running the script as a stand-alone program which uses gimp as a library. This is exactly what I am looking for. I tried it with some code from one of my working python plugins. I removed the "register" code and inlined the relevant gimp calls.

Here is the simple python script: -- begin ---
#!/usr/bin/python

from gimpfu import *

width = 100 height = 100

print "before call to gimp.Image" img = gimp.Image(width, height, RGB) print "after call to gimp.Image"

layer = gimp.Layer(img, "layname", width, height, RGBA_IMAGE, 100, NORMAL_MODE)
img.add_layer(layer, 0)
pdb.gimp_image_set_active_layer(img, layer) draw = pdb.gimp_image_get_active_drawable(img)

# fill solid red gimp.set_foreground((255,0,0))
pdb.gimp_selection_all(img)
pdb.gimp_edit_bucket_fill(draw,0,0,100,0,0,0,0)

filename="temp.tga" pdb.file_tga_save(img,draw,filename,filename,0,0) gimp.delete(img)
--- end ---

The first problem was that python couldn't find the gimpfu module but once I found it and added it to the path I ran into another problem:

$ PYTHONPATH=/usr/lib/gimp/2.0/python ./simple before call to gimp.Image

(process:11416): GLib-CRITICAL **: g_hash_table_lookup: assertion `hash_table != NULL' failed

LibGimpBase-ERROR **: could not find handler for message: 5 aborting...
Aborted
$

Does anyone know what any of the above errors mean? It seems to fail in the first call to gimp i.e. gimp.Image() I'm not sure why the only gimpfu on my system (a stable gentoo box) is located in a 2.0 directory. My gimp version is 2.2.8 and my python version is 2.4.2

The package manager claims that the gimpfu file belongs to the latest gimp package:
# locate gimpfu
/usr/lib/gimp/2.0/python/gimpfu.py
/usr/lib/gimp/2.0/python/gimpfu.pyc
/usr/lib/gimp/2.0/python/gimpfu.pyo
# equery b /usr/lib/gimp/2.0/python/gimpfu.py [ Searching for file(s) /usr/lib/gimp/2.0/python/gimpfu.py in *... ] media-gfx/gimp-2.2.8-r1 (/usr/lib/gimp/2.0/python/gimpfu.py)

Am I supposed to be able to call gimp from a standalone python program like this?

Robert.

Manish Singh
2005-11-23 10:38:58 UTC (over 18 years ago)

run script located in an arbitrary directory

On Mon, Nov 21, 2005 at 05:33:22PM -0800, Robert Kleemann wrote:

michael chang wrote:

perl scripts with the GIMP module can be loaded just like any executable script; for example, if I have a script that uses GIMP called myfile.pl and I go to that directory and call ./myfile.pl, it will run.

Thanks for the idea. I never thought of running the script as a stand-alone program which uses gimp as a library. This is exactly what I am looking for. I tried it with some code from one of my working python plugins. I removed the "register" code and inlined the relevant gimp calls.

Am I supposed to be able to call gimp from a standalone python program like this?

No, this does not work. Python-Fu scripts must be invoked from within GIMP. I wish michael chang actually would check his facts once in a while instead of posting wrong information.

The perl bindings do the run from the command line trick by having GIMP run a plugin that listens on a socket for commands to evaluate. The script will proxy over commands to the server. If no GIMP is running, the script starts one up.

You could code up similar functionality for Python-Fu. I don't know your skill level, but it wouldn't be too hard for someone with reasonable Python and GIMP clue, and if done right, worthy of being folded into the distribution.

Another option is to code up a batch mode evaluator for python. Then you could provide arbitrary code on standard input. This is less complex to implement than the above.

You could write a simple proxy script that lives in the plugin dir that imports your real script and runs it.

And finally, you could follow Carol's suggestion in her earlier mail, that of defining another plug-in dir, and optionally selecting a different config to only pull that in when you need it. This would require no additional code at all.

-Yosh

Robert Kleemann
2005-11-26 20:52:09 UTC (over 18 years ago)

run script located in an arbitrary directory

Thanks Yosh for the definitive answer. I've never looked at the gimp's code base so that would be a huge effort for me to fix this small problem.

I tried Carol's solution of a custom gimprc and that seems to be a good enough solution. In order to get it to work I had to first load the standard plugins so my gimprc looked like the following:

(plug-in-path "/home/robert/custom-plug-ins:/usr/lib/gimp/2.0/plug-ins")

The directories will probably change when the gimp version changes but since the scripts will likely have to be changed as well it's not a big deal.

Thanks to everyone for their help!

Robert.

Carol Spears
2005-11-26 23:18:25 UTC (over 18 years ago)

run script located in an arbitrary directory

On Sat, Nov 26, 2005 at 11:52:09AM -0800, Robert Kleemann wrote:

(plug-in-path "/home/robert/custom-plug-ins:/usr/lib/gimp/2.0/plug-ins")

The directories will probably change when the gimp version changes but since the scripts will likely have to be changed as well it's not a big deal.

the ability to show the new version to the old locations will still be there though. through the preferences the same way.

they try to make things backwards compatible and usually the changes needed are minor.

carol