PDA

View Full Version : Auto start a program on start up?



KirkD
9th October 2009, 06:16 AM
I just installed TuxGuitar - very cool - and to get the sound to work I had to install Timidity++ as well. Before I start TuxGuitar I have to execute:

timidity -iA -Os

in a terminal window first, which is kind of a pain to do every time I run TuxGuitar.

How do I get this line to execute on startup such that timidity is running when I start up? I tried adding that line to rc.local - no luck.

-Kirk

Hlingler
9th October 2009, 06:24 AM
You can:
> place an auto-launcher file in folder ~/.config/autostart/ to (surprise!) auto-start timidity (with the options that you listed) when you log into the desktop; the file might be named 'timidity-auto.desktop', and contain, for example:
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=timidity-auto
Exec=timidity -iA -Os
Terminal=true
NotShowIn=
Comment[en_US]=Input Method starter
X-GNOME-Autostart-enabled=false> alias (in ~/.bashrc) tuxguitar to execute the timidity (with options) first; perhaps:
alias tg='timidity -iA -Os; tuxguitar'

V

P.S. Note that if Timidity should only be running when needed for tuxguitar, then the alias is better, if auto-starting Timidity upon desktop login may interfere with other A/V operations.

KirkD
9th October 2009, 04:14 PM
Hlinger,

Thank you for the tips! I like the alias idea best for the very reasons you mentioned, and will probably approach it this way. How do I get access to the command line used by the Fedora program launcher GUI? When I go to the Fedora Button -> Multimedia -> TuxGuitar, where do I adjust the command line used to start TG? I searched a bit last night in hopes that I could just prefix with the timidity line, but I didn't find it.

-Kirk

Hlingler
9th October 2009, 04:21 PM
Umm... I don't know ? I have F11-LXDE, which uses the OpenBox Window Manager, and I don't know how to edit GNOME desktop launchers. You have actually found a third option: altering the desktop launcher itself (only applies to the user logged into desktop). OR: you could edit (as root user) the tuxguitar system launcher (somewhere in folder /usr/share/applications/...) to contain the command line ('Exec=...') as shown above. That'll make it so for all users. I'd go with:
Exec=timidity -iA -Os; tuxguitarV

KirkD
9th October 2009, 04:23 PM
Glad to see I found that third option on my own. 8^)

I'm actually using KDE, but I doubt that changes things much. I'll dig around a little further and see what I can find. Hmmm....

Hlingler
9th October 2009, 04:34 PM
KDE4 ? Try right-clicking on the menu entry for tuxguitar.

What this essentially does is: copies the system launcher file from folder /usr/share/applications/... into your personal ~/.kde4/... folder, then applies whatever edits you make. You can manually do the same thing by... well, copying the system launcher to the correct folder in your HOME directory (I think: ~/.kde4/share/applnk/ maybe ???), and making the edits. You may need to logout/in to apply the changes to your personal desktop menus.

V

KirkD
9th October 2009, 04:45 PM
Yep, KDE4. I tried the right-click option on TuxGuitar and it didn't give me any option to change anything. I only had options to execute the program or move its location.

I'm away from the system right now, but I'll do a bit more investigation once I have it back in front of me.

KirkD
10th October 2009, 06:31 AM
I found the KDE Menu Editor which gives me access to all the Program Launcher details. From here I changed

tuxguitar %f (the default value I found)

to

timidity -iA -Os; tuxguitar %f

It seems that timidity launches but tuxguitar never comes up. So, I added an ampersand as such:

timidity -iA -Os &; tuxguitar %f

but no luck.

Essentially I need to have the alias option Hilinger suggested attached to the Program Launcher icon for TG. Any ideas??

-Kirk

Hlingler
10th October 2009, 06:35 AM
Hmm... try:
timidity -iA -Os && tuxguitar %f

in the launcher editor. Or: create the alias, then edit the launcher to execute the alias (Exec=tg).

V

KirkD
10th October 2009, 06:40 AM
Update:

I changed the line I mentioned above to:

timidity -iA -Os & tuxguitar %f

which simply removes the ';' after the ampersand. Seems odd, but it works. Now when I fire of TuxGuitar from the Program Launcher, timidity starts, TuxGuitar starts, and TG selects the appropriate timidity port automagically.

Next question - how do I ensure that timidity is killed when TG is closed? Timitidy doesn't seem to interfere with other audio - I tested Audacity, YouTube, and Banshee - but for future reference, how could I go about killing timidity on TG exit?


Hlinger - looks like we crossed in the ether. 8^) Thanks for the tip. Any idea how to kill timidity when TG gets closed??

Hlingler
10th October 2009, 06:52 AM
Must brush up on my command syntax - that single ampersand seems odd indeed... .
Any idea how to kill timidity when TG gets closed??No, not easily (that I know of - but hey, I'm not batting too well here): you would have to write a whole new shell script to run the two, with a call to pkill timidity upon tuxguitar close. But since it does not create problems... .

V

P.S. I see your concern (I think): each time you start (and close) tuxguitar, you have yet another instance of timidity running in the background.

KirkD
10th October 2009, 07:04 AM
Must brush up on my command syntax - that single ampersand seems odd indeed... .No, not easily (that I know of - but hey, I'm not batting too well here): you would have to write a whole new shell script to run the two, with a call to pkill timidity upon tuxguitar close. But since it does not create problems... .

V

P.S. I see your concern (I think): each time you start (and close) tuxguitar, you have yet another instance of timidity running in the background.

Exactly! I can probably deal with only one instance and keeping it in mind, but it gets a little sloppy. Maybe I'll brush up on my syntax too and see if I can come up with a crazy piped line on the order of:

timidity -iA -Os & tuxguitar; kill -9 | ps -A | grep timidity

Essentially when TG stops, get a process list, grep out timidity, pull out the PID, and send it to kill -9. I'm reasonably sure I can build such a line, but it seems a teeny bit of a hack. 8^)

BTW - what should the double ampersand do versus the single that I'm using? (Heading to bed, so I'll check in tomorrow morning. Thanks for all your help now and in the past!!)

Hlingler
10th October 2009, 07:08 AM
Double ampersand means "if the first command succeeds, then and only then...". Incidentally: I mentioned pkill, because using it does not require that you know the PID. ;)

Perhaps something like this might work:
timidity -iA -Os & tuxguitar; pkill timidity

Not exactly sure if that would be feasible from a desktop launcher though. Note also that, if that actually does work, then pkill would terminate ALL open instances of timidity, with prejudice. :D

V

KirkD
12th October 2009, 05:29 AM
That did the trick! Thanks, again!!