method to preclude multiple launchings of an application

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
wpshooter
Level 6
Level 6
Posts: 1455
Joined: Sun May 22, 2011 8:06 am

method to preclude multiple launchings of an application

Post by wpshooter »

Is there a way to preclude the ability of launching multiple/simultaneous launchings of an application (say, for instance Evolution) in Linux Mint Mate ?

And that can be applied to just desired applications and not on a wholesale basis.

Thanks.
Last edited by LockBot on Fri Feb 17, 2023 11:00 pm, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Mint 21.3 Mate.

SERVICE > competition
User avatar
hglee
Level 6
Level 6
Posts: 1422
Joined: Fri Jun 22, 2018 4:31 pm

Re: method to preclude multiple launchings of an application

Post by hglee »

wpshooter wrote: Wed Aug 17, 2022 11:11 am Is there a way to preclude the ability of launching multiple/simultaneous launchings of an application (say, for instance Evolution) in Linux Mint Mate ?

And that can be applied to just desired applications and not on a wholesale basis.


Write a simple Bash script that checks for a special empty file. If that special empty file is present, abort. Otherwise, create the special empty file and invoke the app. When app is finshed, it returns to script which then deletes the special empty file.


You (system user) don't invoke the app. You invoke the script. Your script invokes the app.

The actual app would be oblivious to all this. Your script is in charge of runs. One script per app, one app per script. One special file per app.

Your script could have the same filename as the app, so if you put the script file ahead of the app file in the system Command Path, your script could intercept indirect calls to the app. Otherwise you might need to "hide" the app, so it can't be called directly.



Linux Mint 21 Vanessa, MATE 1.26.0, kernel 5.15.0*, Dell 2-in-1
AMD Ryzen 7 5825U / Barcelo iGPU - 14" WUXGA Touchscreen
MediaTek MT7921 WiFi-6 BT-5.2; 32GB DDR4@3200MHz; XPG 2TB-NVMe
User avatar
hglee
Level 6
Level 6
Posts: 1422
Joined: Fri Jun 22, 2018 4:31 pm

Re: method to preclude multiple launchings of an application

Post by hglee »

...

Here's a very rudimentary but functional Terminal example. Run my_xed script to invoke xed editor. Script allows only one instance of xed.

#!/bin/bash
#
# this script is /usr/local/bin/my_xed
#
# our special empty file (SEF) for this app, with Hidden attribute:
SEF="$HOME/.special_file_1234z"
#
# check for existence of app's special empty file, and ABORT if found...
[ -f $SEF ] && exit 1
# otherwise CREATE app's special empty file...
touch $SEF
# INVOKE the app...
/usr/bin/xed $1
# app has completed, so DELETE its special empty file ...
rm $SEF
# all done ...
exit 0
#
# Example script does no error or other sanity checks.
#

This isn't MATE specific. It's DE agnostic, except maybe for the presence of xed -- though every Mint has that.

Most apps have their binary file in the /usr/bin subdirectory. You could steer end-users to your script by placing it in a subdirectory that's ahead of /usr/bin in the Linux command path, such as /usr/local/bin. Or you could rename the original binary, then create a soft-link of the original name in /usr/bin that points to your script (which can invoke the renamed app) -- but note that this does not account for system software updates that may overwrite your link.


Linux Mint 21 Vanessa, MATE 1.26.0, kernel 5.15.0*, Dell 2-in-1
AMD Ryzen 7 5825U / Barcelo iGPU - 14" WUXGA Touchscreen
MediaTek MT7921 WiFi-6 BT-5.2; 32GB DDR4@3200MHz; XPG 2TB-NVMe
Locked

Return to “MATE”