LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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
 
LinkBack Search this Thread
Old 06-11-2004, 02:15 PM   #1
bluedude2288
Member
 
Registered: Nov 2003
Location: Akron, Ohio
Distribution: -->Debian<--, RH, Android, Ubuntu
Posts: 62

Rep: Reputation: 15
Script to run a program


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 02:23 PM.
 
Old 06-11-2004, 02:39 PM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,104

Rep: Reputation: Disabled
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.
 
Old 06-11-2004, 04:13 PM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
Easier yet:
Code:
#!/bin/bash
killall gmplayer
gmplayer $1
If you call the script myplayer, then start with:

shell$ ./myplayer song_to_play.mp3
 
Old 06-11-2004, 05:13 PM   #4
bluedude2288
Member
 
Registered: Nov 2003
Location: Akron, Ohio
Distribution: -->Debian<--, RH, Android, Ubuntu
Posts: 62

Original Poster
Rep: Reputation: 15
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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


All times are GMT -5. The time now is 10:52 AM.

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
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration