LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 06-11-2004, 03:15 PM   #1
bluedude2288
Member
 
Registered: Nov 2003
Distribution: Gentoo Stage 1 2004.2
Posts: 59
Thanked: 0
Script to run a program


[Log in to get rid of this advertisement]
I want to write a small BASH script that will run when I play and mp3, i want it to check if gmplayer is open then if it is kill it and reopen it with the new song if its not open just open it and play the song, how do i do this, the reason i need this is if i go to play a song and one is playing it opens another so i get errors saying sound card is in use.

Last edited by bluedude2288; 06-11-2004 at 03:23 PM..
bluedude2288 is offline     Reply With Quote
Old 06-11-2004, 03:39 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware 13.0, -current
Posts: 3,887
Blog Entries: 1
Thanked: 27
ps, grep, kill, test, if...then...else...fi, mplayer flags. Those would be the main ingredients. Just grep ps for whether it's running and kill it if it is, and don't if it's not. The man pages for those items will give full details.

Ought to be an option to switch songs in mplayer, but I dunno - I use mplayer for video and xmms for audio.
slakmagik is offline     Reply With Quote
Old 06-11-2004, 05:13 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,498
Thanked: 44
Easier yet:
Code:
#!/bin/bash
killall gmplayer
gmplayer $1
If you call the script myplayer, then start with:

shell$ ./myplayer song_to_play.mp3
Hko is offline     Reply With Quote
Old 06-11-2004, 06:13 PM   #4
bluedude2288
Member
 
Registered: Nov 2003
Distribution: Gentoo Stage 1 2004.2
Posts: 59
Thanked: 0

Original Poster
Ok thanks for the replies, but one other question, how do you send a key command to a specific program from in the script, this is because when i do a killall i get an error dialog saying terminated by 15 or something similar, insted to close the program i'd like to send it the escape key or q key to close it.
bluedude2288 is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a script run through a shell program... okeyla Linux - Newbie 1 09-15-2005 11:06 AM
how to run a shell script type program redragon7964 Linux - Newbie 1 04-06-2004 03:03 AM
run shell script in c program u4u Linux - General 1 02-14-2004 03:48 PM
i want to run a script or program at boot time!! FreakboY Linux - Newbie 9 10-12-2003 09:03 AM
How do I automatically run at boot an X program or script cmisip Linux - General 4 01-05-2003 07:30 PM


All times are GMT -5. The time now is 06:43 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration