You are not logged in.
Hi,
I would like to automatically disable my XScreenSaver and Gnome Power Management when I start MPlayer.
I found different solution, but the only one that works for me is Caffeine (in the AUR).
This program sits in the tray and disable all screensaver / power managemet apps running when certain programs are started.
However, I don't like to have an app running all the time in my tray since I watch movies not that often: luckily Caffeine also has a -a option that activates it when it started. A good piece of software indeed!
So let's come to the question:
How can I start caffeine -a every time I use mplayer or gnome-mplayer?
Maybe through aliases in .bashrc? Any help / hint would be appreciated!
Thank you!
Last edited by rent0n (2010-01-04 16:01:07)
rent0n@deviantART | rent0n@bitbucket | rent0n@identi.ca | LRU #337812
aspire: Acer Aspire 5920 Arch Linux x86_64 | beetle: Gericom Beetle G733 Arch Linux i686
Offline
alaises would be easy:
alias mplayer='caffeine -a &>/dev/null &; mplayer'
but if you expanded to a function you could do something more complicated like, also kill caffiene when the movie is over:
mplayer() {
PID=$(pgrep caffeine)
if [ -z "$PID" ]; then
caffeine -a &>/dev/null &
PID=$!
fi
/usr/bin/mplayer $*
kill $PID
}
note: untested.
Last edited by brisbin33 (2010-01-03 20:31:49)
//github/
Offline
Thank you brisbin, you are always so helpful.
The alias seems not to work, I got a bash syntax error:
┌─[enrico@beetle][~]
└─[$] alias mplayer='caffeine -a &>/dev/null &; mplayer'
┌─[enrico@beetle][~]
└─[$] mplayer
bash: syntax error near unexpected token `;'
Removing & before ; or replacing &; with && doesn't work because mplayer will start only when caffeine is closed.
Is there a way to mke the alias work as expected?
Regarding the function, how can I use it?
I mean where do I store it and how do I call mplayer?
rent0n@deviantART | rent0n@bitbucket | rent0n@identi.ca | LRU #337812
aspire: Acer Aspire 5920 Arch Linux x86_64 | beetle: Gericom Beetle G733 Arch Linux i686
Offline
using the function is exactly the same as the alias, place it in bashrc and call it by name (mplayer in my example). i never tried an alias as i had written, i suppose you can't put multiliners as an alias (i.e. two commands separated by ';').
edit: and just as with the alias, you can also do all this from CLI for testing purposes. an example:
//blue/0/~/ tester() {
// echo 'hey look, im a function'
// }
//blue/0/~/ tester
hey look, im a function
//blue/0/~/
('//' is just my PS2 prompt)
Last edited by brisbin33 (2010-01-03 23:24:48)
//github/
Offline
have you tried the heartbeat option in mplayer??
smth like this:
heartbeat-cmd="gnome-screensaver-command -p"
in ~/.mplayer/config
Last edited by damjan (2010-01-03 23:52:20)
Offline
@damjan: I tried that but it has a big problem: video freezes every 30 second for a couple of seconds and movies are unwatchable...Moreover it works only for xscreensaver and not for gpm.
@brisbin33: The functions work perfectly, thank you.
However, they are called only if I start the programs from the terminal.
Is it possible to have the functions called also when I double click on a avi file that is associated with gnome-mplayer?
rent0n@deviantART | rent0n@bitbucket | rent0n@identi.ca | LRU #337812
aspire: Acer Aspire 5920 Arch Linux x86_64 | beetle: Gericom Beetle G733 Arch Linux i686
Offline
Is it possible to have the functions called also when I double click on a avi file that is associated with gnome-mplayer?
in this case i'd make it a script.
put just the body of the function in a file, make it executable, and place it somewhere in your $PATH. (if you do name it 'mplayer' make sure it's ahead of /usr/bin in your path or you'll never get to it.).
once that's setup and working, you can define that script as your default handler for avis, mpgs, or whatever.
//github/
Offline
Great, I've created mplayer-caffeine and gnome-mplayer-caffeine in /usr/bin and they handle well most files.
There is only a problem in files that contain spaces in their names: they are not played at all.
Have you got any idea on how to get rid of this and play correctly file with spaces?
Thanks!
EDIT: Found out: simply include $* in double quotes ("$*") works.
Awesome, thank you brisbin33!
Reporting here /usr/bin/gnome-mplayer-caffeine:
#!/bin/bash
PID=$(pgrep caffeine)
if [ -z "$PID" ]; then
caffeine -a &>/dev/null &
PID=$!
fi
/usr/bin/gnome-mplayer "$*"
kill $PID
Last edited by rent0n (2010-01-04 16:00:36)
rent0n@deviantART | rent0n@bitbucket | rent0n@identi.ca | LRU #337812
aspire: Acer Aspire 5920 Arch Linux x86_64 | beetle: Gericom Beetle G733 Arch Linux i686
Offline
What's the difference between "$*" and "$@"?
They seem both to handle well filenames with spaces.
rent0n@deviantART | rent0n@bitbucket | rent0n@identi.ca | LRU #337812
aspire: Acer Aspire 5920 Arch Linux x86_64 | beetle: Gericom Beetle G733 Arch Linux i686
Offline
as was taught to me in IRC
//blue/0/~/ tester() { for arg in "$*"; do echo $arg; done; for arg in "$@"; do echo $arg; done; }
//blue/0/~/ tester "a b c"
a b c
a b c
//blue/0/~/ tester "a b" c
a b c
a b
c
//blue/0/~/ tester a b c
a b c
a
b
c
//blue/0/~/
//github/
Offline
So "$*" is more similar to a scalar while "$@" acts as an array.
So the final solution is (reporting here, you never know):
$ sudo touch /usr/bin/gnome-mplayer-caffeine && sudo chmod +x gnome-mplayer-caffeine && sudo nano /usr/bin/gnome-mplayer-caffeine
Add:
#!/bin/bash
PID=$(pgrep caffeine)
if [ -z "$PID" ]; then
caffeine -a &>/dev/null &
PID=$!
fi
/usr/bin/gnome-mplayer "$@"
kill $PID
Save and close.
Now associate .avi files with gnome-mplayer-caffeine and it's done!
rent0n@deviantART | rent0n@bitbucket | rent0n@identi.ca | LRU #337812
aspire: Acer Aspire 5920 Arch Linux x86_64 | beetle: Gericom Beetle G733 Arch Linux i686
Offline