]> git.lyx.org Git - lyx.git/blob - development/MacOSX/inkscape
comment
[lyx.git] / development / MacOSX / inkscape
1 #!/bin/bash
2
3 # \file inkscape
4 # wrapper start script for Inkscape.app on Mac
5 #
6 # This file is part of LyX, the document processor.
7 # Licence details can be found in the file COPYING.
8 #
9 # \author Stephan Witt
10 # Full author contact details are available in file CREDITS.
11
12 unset DISPLAY
13
14 # check for file arguments with relative path names
15 # convert them to absolute path names
16 # inkscape on Mac changes the working directory
17 # this invalidates relative path names
18 startinkscape() {
19         inkscape="$1" ; shift
20         pwd=$(pwd)
21         iparams=( "$@" )
22         oparams=()
23         # pre 1.0 application has cmd line utility in resources
24         # this utility needs the explicit option to suppress gui
25         # 1.0 don't have it and fails to start with it
26         case "${inkscape}" in
27         */Resources/*)
28                 wogui="--without-gui"
29                 ;;
30         esac
31         for i in ${!iparams[@]}; do
32                 # echo $i "=>" "${iparams[$i]}"
33                 case "${iparams[$i]}" in
34                 --file=/*|--export-pdf=/*|--export-eps=/*|--export-png=/*|--export-emf=/*|--export-wmf=/*|--export-ps=/*|--export-ps-level=/*|--export-pdf-version=/*)
35                         oparams+=( "${iparams[$i]}" )
36                         ;;
37                 --file=*|--export-pdf=*|--export-eps=*|--export-png=*|--export-emf=*|--export-wmf=*|--export-ps=*|--export-ps-level=*|--export-pdf-version=*)
38                         oparams+=( "${iparams[$i]//=/=${pwd}/}" )
39                         ;;
40                 --without-gui|-z)
41                         # ignore this argument - its provided below anyway
42                         ;;
43                 *)
44                         oparams+=( "${iparams[$i]}" )
45                         ;;
46                 esac
47         done
48         exec "${inkscape}" ${wogui} "${oparams[@]}"
49 }
50
51 # try to find the inkscape installation...
52 # at first try the well known location for Inkscape 1.0
53 # but check for Inkscape 0.92.x too and skip this if it's in Resources
54 RESDIR="/Applications/Inkscape.app/Contents/MacOS"
55 if [ ! -f "/Applications/Inkscape.app/Contents/Resources/bin/inkscape" -a -f "${RESDIR}"/inkscape -a -x "${RESDIR}"/inkscape ]; then
56         startinkscape "${RESDIR}"/inkscape "$@"
57         exit 0
58 fi
59 # this failed... so try PATH expansion to start the inkscape shell wrapper
60 # Now continue the check with pre 1.0 inkscape application and the PATH
61 IFS=":" read -ra DIRLIST <<< "${PATH}"
62 for BINDIR in "/Applications/Inkscape.app/Contents/Resources/bin" "${DIRLIST[@]}" ; do
63         RESDIR=$(dirname "${BINDIR}")
64         if [ -f "${RESDIR}"/bin/inkscape -a -x "${RESDIR}"/bin/inkscape ]; then
65                 startinkscape "${RESDIR}"/bin/inkscape "$@"
66                 exit 0
67         fi
68 done
69 # report error and exit with failure status
70 exec 1>&2
71 echo Could not find Inkscape binary.
72 exit 1