#!/bin/sh

# This is a helper program to execute saved command files,
# by sending them to a running instance of Kupfer.

export TEXTDOMAIN='kupfer'
export TEXTDOMAINDIR='/usr/share/locale'

PYTHON='/usr/bin/python'

if test ! -f "$1"
then
	echo "A file argument required"
	exit 1
fi

SERVICE="io.github.kupferlauncher"
OBJ="/io/github/kupferlauncher"
IFACE="io.github.kupferlauncher.Listener"

while test $# != 0
do
	FILE=$(readlink -f "$1")
	dbus-send --print-reply --dest=$SERVICE $OBJ \
		$IFACE.ExecuteFileOnDisplay string:"$FILE" \
		string:"$DISPLAY" string:"$DESKTOP_STARTUP_ID" \
		> /dev/null 2>&1
	KUPFER_RUNNING=$?

	if test $KUPFER_RUNNING != 0
	then
		# NOTE: If you change this string, you have to change
		# it inside kupfer/version.py as well.
		zenity --info --text "$(gettext 'Could not find running Kupfer')" &
		exit 1
	fi
	shift
done
