Dia command line not working

I've got a problem with using Dia from the command line on OSX 10.7.4. I downloaded and installed the OS X dmg from http://dia-installer.de/download/macosx.html I've been using it to create graphics for a paper and absolutely love it.

I'm using a makefile to call pdflatex, bibtex, and R so that that it will build everything from scratch if need be, but can't get Dia's command line to work.

I want to use the command line with -e and -t to export the graphics to a specific directory so that pdflatex can put them in the pdf. (http://dia-installer.de/doc/en/re01.html)

The problem that I'm running into is that anytime I call it from the terminal, it brings up the GUI. Even if I give move to /Applications/Dia.app/Content/Resources/bin/ and use the command "./dia -v". It gives me a bunch of errors about "Input method" and then shows the GUI.

I looked on the Dia FAQ and it has a lot of information for the Windows command line, but nothing for OS X.

I'm hoping that someone here has run into this before and knows how to get it to work.


On the Mac, dia (specifically /Applications/Dia.app/Content/Resources/bin/dia) is just a shell script wrapper to the compiled dia-bin binary. It sets a number of environmental variables, and then finishes by executing Dia as a GUI:

exec "$CWD/dia-bin" --integrated

You can make a copy (e.g. cp -p dia dia-cmd) and edit that last line in dia-cmd to become:

"$CWD/dia-bin" $@

and then you can use it as dia-cmd within the terminal.

Note: I found that for my locale (en_US.UTF-8), at least, running dia-cmd in the terminal was way too chatty about trying to determine the correct locale, spewing ignorable warnings:

Warning: AppleCollationOrder setting not found, using AppleLocale.
Setting Language: en.UTF8

(process:33043): Gdk-WARNING **: locale not supported by C library

(process:33043): Gtk-WARNING **: Locale not supported by C library.
    Using the fallback 'C' locale.

You can eliminate that by also commenting-out those lines in dia-cmd, and manually forcing the correct locale:

## LANGSTR=`defaults read .GlobalPreferences AppleCollationOrder 2>/dev/null`
## if [ "x$LANGSTR" == "x" ]
## then
##    echo "Warning: AppleCollationOrder setting not found, using AppleLocale." 1>&2
##    LANGSTR=`defaults read .GlobalPreferences AppleLocale 2>/dev/null | \
##            sed 's/_.*//'`
## fi

# NOTE: Have to add ".UTF-8" to the LANG since omitting causes Dia
#       to crash on startup in locale_from_utf8().
## export LANG="$LANGSTR.UTF8"
 export LANG="en_US.UTF-8"
## echo "Setting Language: $LANG" 1>&2

Voila:

MYMACHINE:~ lars$ /Applications/Dia.app/Contents/Resources/bin/dia-cmd -v
Dia version 0.97.2, compiled 18:51:13 Mar 17 2012

Based on the accepted answer, I created dia-cli and a shortcut, dia:

cd /Applications/Dia.app/Contents/Resources/bin
cp -p dia dia-cli

cd /usr/local/bin
touch dia
sudo chmod +x dia

Contents of /Applications/Dia.app/Contents/Resources/bin/dia-cli:

...
"$CWD/dia-bin" $@

Contents of /usr/local/bin/dia:

PATH=$PATH:/Applications/Dia.app/Contents/Resources/bin
/Applications/Dia.app/Contents/Resources/bin/dia-cli "$@"