2005-09-21 10:04:26 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# ron@18james.com, 11 Dec 2003
|
2007-02-18 22:35:22 +00:00
|
|
|
# With modifications by Angus Leeming, tweaked by Bennett Helm 21 Jan 2007
|
|
|
|
|
|
|
|
parse_serverpipe()
|
|
|
|
{
|
2010-07-27 19:37:35 +00:00
|
|
|
test -r "$1" || {
|
|
|
|
echo "Usage: parse_serverpipe lyxrc" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2007-02-18 22:35:22 +00:00
|
|
|
|
2010-07-27 19:37:35 +00:00
|
|
|
# The output of this sed script is output to STDOUT
|
|
|
|
LYXPIPE=`sed -n '/^\\\\serverpipe /{
|
2007-02-18 22:35:22 +00:00
|
|
|
# First consider that the file path may be quoted
|
|
|
|
s/^ *\\\\serverpipe \{1,\}\"\([^"]\{1,\}\)\" *$/\1/
|
|
|
|
tfound
|
|
|
|
|
|
|
|
# Now, unquoted
|
|
|
|
s/^ *\\\\serverpipe \{1,\}\(.*\)/\1/
|
|
|
|
s/ *$//
|
|
|
|
|
|
|
|
:found
|
|
|
|
# Change from single to double shell quoting temporarily...
|
|
|
|
'"
|
|
|
|
s@^~/@${HOME}/@
|
|
|
|
# Revert to single shell quotes
|
|
|
|
"'
|
|
|
|
|
|
|
|
p
|
|
|
|
q
|
|
|
|
}' "$1"`
|
2010-07-27 19:37:35 +00:00
|
|
|
echo "${LYXPIPE}"
|
2007-02-18 22:35:22 +00:00
|
|
|
}
|
|
|
|
|
2005-09-21 10:04:26 +00:00
|
|
|
|
2007-02-18 22:35:22 +00:00
|
|
|
USER_SUPPORT="${HOME}/Library/Application Support"
|
|
|
|
test -d "${USER_SUPPORT}" || {
|
2010-07-22 16:35:25 +00:00
|
|
|
echo "Something horrible is going on. No user support directory ${USER_SUPPORT}" >&2
|
2007-02-18 22:35:22 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2017-09-14 06:52:38 +00:00
|
|
|
# we prefer newer lyx releases here...
|
|
|
|
for LYXDIR in LyX-2.4 LyX-2.3 LyX-2.2 LyX-2.1 LyX-2.0 LyX-1.6 LyX-1.5 LyX-1.4 LyX
|
2007-02-18 22:35:22 +00:00
|
|
|
do
|
|
|
|
ABS_USER_LYXDIR="${USER_SUPPORT}/${LYXDIR}"
|
|
|
|
test -d "${ABS_USER_LYXDIR}" || {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
PREFERENCES="${ABS_USER_LYXDIR}/preferences"
|
|
|
|
test -r "${PREFERENCES}" || {
|
|
|
|
echo "Failed to find PREFERENCES: ${PREFERENCES}" >&2
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
# preferences file exists.
|
|
|
|
# See if it contains a \\serverpipe entry
|
2017-09-14 06:50:42 +00:00
|
|
|
LYXPIPE=$(parse_serverpipe "${PREFERENCES}")
|
2017-09-14 06:52:38 +00:00
|
|
|
# break if pipe entry and pipe detected
|
|
|
|
# hopefully it's the correct LyX instance...
|
2010-07-27 19:37:35 +00:00
|
|
|
if [ -n "$LYXPIPE" -a -p "$LYXPIPE".in ]; then
|
|
|
|
break
|
|
|
|
fi
|
2007-02-18 22:35:22 +00:00
|
|
|
done
|
|
|
|
|
2010-07-27 19:37:35 +00:00
|
|
|
# echo "preferences file sets lyxpipe as ${LYXPIPE}"
|
2007-02-18 22:35:22 +00:00
|
|
|
|
|
|
|
test -z "${LYXPIPE}" && {
|
2017-09-14 07:00:16 +00:00
|
|
|
ABS_SYSTEM_LYXDIR=$(dirname "$0")
|
|
|
|
ABS_SYSTEM_LYXDIR=$(dirname "${ABS_SYSTEM_LYXDIR}")"/Resources"
|
2007-02-18 22:35:22 +00:00
|
|
|
test -d "${ABS_SYSTEM_LYXDIR}" || {
|
2010-07-27 19:37:35 +00:00
|
|
|
echo "Failed to find ABS_SYSTEM_LYXDIR: ${ABS_SYSTEM_LYXDIR}" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
LYXRC_DIST="${ABS_SYSTEM_LYXDIR}/lyxrc.dist"
|
|
|
|
test -r "${LYXRC_DIST}" || {
|
|
|
|
echo "Failed to find LYXRC_DIST: ${LYXRC_DIST}" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2007-02-18 22:35:22 +00:00
|
|
|
|
|
|
|
# lyxrc.dist exists
|
|
|
|
# See if it contains a \\serverpipe entry
|
2017-09-14 06:50:42 +00:00
|
|
|
LYXPIPE=$(parse_serverpipe "${LYXRC_DIST}")
|
2007-02-18 22:35:22 +00:00
|
|
|
}
|
|
|
|
|
2010-07-27 19:37:35 +00:00
|
|
|
if [ -n "$LYXPIPE" -a -p "$LYXPIPE".in ]; then
|
2020-02-22 11:11:42 +00:00
|
|
|
MAC_LYXPIPE_CONTENTS="LYXCMD:macdvix:server-goto-file-row:$1 $2"
|
2010-07-27 19:37:35 +00:00
|
|
|
# echo "$MAC_LYXPIPE_CONTENTS"
|
|
|
|
echo "$MAC_LYXPIPE_CONTENTS" > "${LYXPIPE}".in || { echo "Cannot write to lyxpipe." ; exit 2 ; }
|
2017-09-15 06:16:50 +00:00
|
|
|
while read line ; do
|
2017-09-14 06:57:52 +00:00
|
|
|
echo LyX said: $line
|
2017-09-15 06:16:50 +00:00
|
|
|
done < "${LYXPIPE}".out || { echo "Cannot read from lyxpipe." ; exit 2 ; }
|
2020-02-14 11:06:08 +00:00
|
|
|
test -x /usr/bin/osascript && /usr/bin/osascript -e 'tell application id "org.lyx.lyx" to activate'
|
2010-07-27 19:37:35 +00:00
|
|
|
else
|
|
|
|
echo "Our best guess sets lyxpipe as ${LYXPIPE}"
|
|
|
|
echo "But the lyxpipe could not be found."
|
|
|
|
exit 1
|
|
|
|
fi
|
2007-02-18 22:35:22 +00:00
|
|
|
# The end
|
|
|
|
|