You are not logged in.

#1 2013-04-10 14:30:37

cdysthe
Member
Registered: 2009-11-20
Posts: 62

Have a bash script run every time an application is opened.

Hi,

On my Arch box I would like to have a bash script run every time a certain application is opened from the menu. I would prefer a delay of a 5 - 10 seconds after the program opens if that is possible. Could someone please let me know if and how I can achieve this?

Offline

#2 2013-04-10 14:37:28

brebs
Member
Registered: 2007-04-03
Posts: 3,742

Re: Have a bash script run every time an application is opened.

Easy, if your PATH is set up right, so /home/youruser/bin is first in your PATH.

Just have a script in ~/bin/ named the same as your program, which does an exec at the end, e.g.:

#!/bin/bash

export __GL_SYNC_TO_VBLANK=0

exec nice -n -3 /usr/bin/glxgears

Offline

#3 2013-04-10 14:50:50

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Have a bash script run every time an application is opened.

Problem is, OP wants the "meat" of his script to run after the program, which would mean putting it after the exec. But AFAIK, anything after the exec will be ignored. You could call another script to run in the background before the exec, but that seems hackish.

Last edited by alphaniner (2013-04-10 14:57:01)


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#4 2013-04-10 14:54:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,553
Website

Re: Have a bash script run every time an application is opened.

#!/bin/bash

/usr/bin/$@ &

sleep 5

#do something else

Fill in the "do something else" part.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2013-04-10 15:05:09

cdysthe
Member
Registered: 2009-11-20
Posts: 62

Re: Have a bash script run every time an application is opened.

Thanks! Another issue is that this is a program often invoked by a link in the browser as a default action which seems to complicate matters a little.

Offline

#6 2013-04-10 15:06:46

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Have a bash script run every time an application is opened.

cdysthe wrote:

Thanks! Another issue is that this is a program often invoked by a link in the browser as a default action which seems to complicate matters a little.

That's too bad. What do you plan to do about that ?


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#7 2013-04-10 15:09:07

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Have a bash script run every time an application is opened.

Details are always better than vagueness, so how about naming the "certain application" and posting the script you want to run?

Offline

#8 2013-04-10 16:01:34

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,553
Website

Re: Have a bash script run every time an application is opened.

Not only the "certain application", but knowing what browser this is, and how it has been configured to launch anything would be helpful.  Many browsers use mime-type info to determine what program/script to launch.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#9 2013-04-10 19:30:22

briest
Member
From: Katowice, PL
Registered: 2006-05-04
Posts: 468

Re: Have a bash script run every time an application is opened.

Maybe inotfiy (say, incron -- hook the script on IN_OPEN "certain application" binary: wait 5s, check if application is running, as IN_OPEN does not necesssarily mean execution) or auditd (pro: can be hooked to actual execution, con: all it can do is log, so a log-watcher would be needed to do something more elaborate).

Offline

Board footer

Powered by FluxBB