3
#!/bin/sh
...several lines of commands...
mousepad file.txt
zenity --info
...several more lines of commands...
exit

Expected behavior: I command the script (in this case, via a keyboard shortcut). A Mousepad window then opens on my Xfce4 desktop, displaying the contents of file.txt. I perform some text manipulation within same and then manually close said Mousepad window. Next, the commanded Zenity window appears, as expected. I close same manually and the next step of the script executes.

The script works fine if there are no other open Mousepad windows anywhere. However, if I happen to already have one or more Mousepad windows open when I command said script (again, via a keyboard shortcut), here is what now happens:

After said script is so commanded, the expected Mousepad window (the one displaying the contents of file.txt) opens, along with the Zenity window (note that, in this case, said Zenity window opens before the Mousepad window is manually closed by me). This is undesired behavior.

Note that the subject script worked fine when running under Debian Wheezy (using SystemV). However, after a recent upgrade to Debian Jessie (using systemd) I started seeing the changed, undesired behavior. Don't know if said systemd plays into this...

I have tried many things, including the wait command and appending the mousepad line with &&. I've also attempted trapping. Nothing is working for me.

What is causing this to happen and how can I remedy it?

TIA!

3

What you describe is what happens when a program runs some sort of server so that new instances connect to the existing one. If mousapad is running already, it just connects to the existing instance and exits immediately. Since it exits immediately, your script continues and that's why you see zenity.

The fix is simple, there's an option to disable this:

$ mousepad -h
Usage:
  mousepad [OPTION…] [FILES...]

Help Options:
  -h, --help               Show help options
  --help-all               Show all help options
  --help-gtk               Show GTK+ Options

Application Options:
  --disable-server         Do not register with the D-BUS session message bus
  -q, --quit               Quit a running Mousepad instance
  -v, --version            Print version information and exit
  --display=DISPLAY        X display to use

The option is --disable-server so simply change your script to this:

#!/bin/sh
...several lines of commands...
mousepad --disable-server file.txt
zenity --info
...several more lines of commands...
exit
3
  • 1
    Work great now! Apparently, during the upgrade mentioned in the OP, Mousepad adopted a server scheme. I might have caught that myself, except for the fact that I never looked past man mousepad, where the required option is NOT addressed. Lesson Learned: When researching application options, check the help page IN ADDITION TO the man page...
    – Digger
    Nov 11 '20 at 22:13
  • 1
    @Digger huh, that's odd. I guessed this was the case from the behavior you described, and I installed mousepad on my system to check. To my surprise, there was no man page and all I could find was the mousepad -h :)
    – terdon
    Nov 12 '20 at 9:17
  • Please bear in mind that I'm a little behind with my upgrades...I'm currently rocking version 0.3.0 of Mousepad.
    – Digger
    Nov 13 '20 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.