Is there a way to tell an already running x-program to open a file from bash? (I.e. without invoking a new instance of the program.) While I am asking this question in the context of xstata-mp
, I am interested more generally if this kind of solution exists in general for Xorg applications.
I have an x-application (xstata-mp
, proprietary, which is salient to this question as you will learn) which runs swell. I have managed to make a nice launching script that first checks whether xstata-mp
is already running, and if it is, brings it to the foreground, and otherwise launches it. Much like the accepted answer to this question.
My problem is that sometimes I want to open a document used by xstata-mp
(e.g., a .dta
data file, a .do
script file, a .sthlp
help file, etc.). If I double click on such a file's icon, or select the icon and hit <ENTER>
while xstata-mp
is already running, the launch script gets called (it is referenced in the exec
part of xstata-mp
's .desktop
file) and xstata-mp
is raised to the top of the visible windows, but without opening the document.
For what it is worth, checking with pidof
it appears that xstata-mp
does not launch a new xstata-mp
process if I open multiple documents within it (e.g., using <CTRL>-O
); contrast with, say, Firefox
and multiple tabs/sites.
Here is the launch script I would like to modify:
# Check if xstata-mp v17 is running
exit_code_pidof_xstata_mp=$(pidof /usr/local/stata17/xstata-mp)
if xstata-mp v17 IS NOT running, then launch it with argument $1
if [ -z "$exit_code_pidof_xstata_mp" ]
then
/usr/local/stata17/xstata-mp -q $1; exit >/dev/null
but if xstata-mp v17 IS running, then bring it to front instead
else
wmctrl -ia "$(wmctrl -lp | grep "$(pgrep /usr/local/stata17/xstata-mp)" | tail -1 | awk '{ print $1 }')"; exit > /dev/null
fi
xstata-mp --help
and also the things not documented there (like thedoedit
argument) in the official documentation. I feared an answer like yours might be in the offing, but posed my question in the hope that there might be some interface standard for Xorg apps along the lines of my request. (If there is, argument-a
ain't it, by the way. ;). (Also: the-q
option is mos def irrelevant to my concerns here.) – Lexible Feb 21 '22 at 05:34xdotool
which is allows one to manipulate (key strokes, text, pointer input, windows, some related variables, etc.) Xorg programs. When I get my script edited to working, I will compose an answer, but wanted to let know there is a solution for Xorg applications in general! :))) – Lexible Feb 23 '22 at 21:23