#!/bin/bash

# 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'

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

while test $# != 0
do
	FILE=$(realpath -s "$1")
	dbus-send --print-reply --dest=se.kaizer.kupfer /interface \
		se.kaizer.kupfer.Listener.ExecuteFile string:"$FILE" \
		> /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 $"Could not find running Kupfer" &
		exit 1
	fi
	shift
done
