OnSongChange wont work

I've installed 2.5.0alpha from Elimar's repository

in config I've got:
OnSongChange = "/home/pawian/.skrypty/moc_now_play %r - %t [%a]"

to show new song via OSD, unfortunately nothing happens when on songs change

script works (tested manually)

I just tested this and had the same problem.

OnSongChange is working but your environment is missing.

Try adding this (adapt to your local setup) in the head of you script :
<br /> export DISPLAY=:0.0<br /> export XAUTHORITY=/home/pawian/.Xauthority<br />

thanks, after add those exports it really works
btw. there's mistake in variables, in example config is
# %a album<br /> # %r artist

but in practice it is
# %a artist<br /> # %r album

Thanks, I've fixed config.example.

Damian Pietras - MOC developer

Could you add similar function OnMOCStop?

What would be the use for that? I'm aware that the current OnSongChange option is not really enough, but with OnMOCStop it's still probably not enough, so I want to know some use cases.

Damian Pietras - MOC developer

I'm using OnSongChange to show current song with osd_cat, with OnMOCStop I'll can view information that player is stopped (not always it is posible to realize - some tracks, often last tracks on album, includes two songs: first "official" song, some time of silence and "hidden" song).

Also it's possible to shutdown system when music is off (I like to listen to some music when I'm falling in sleep), now I need to run two applications: mocp and shutdown -h

I asked if it's possible. If that function needs a lot of work I'll understand and accept when it will not be merged.
But if it's easy to do, I'm sure some people will use that option.


I have made a copy of the on_song_change function, provided it with a commandline switch and am using it to xosd-display the current song title on keypress (and not only when the songs change). Coming to think of it, it probably would have been better to jut parse the output of `mocp -i`, but I didn't think of that in time. ;)

I suppose your question was aimed rather at what additional events should get a special role, so you may or may not be inspired by my idea of having a custom command executed per cmdline argument. Anyway, I'll take the opportunity to just thank you a lot for the incredibly fine program that moc is.

With the sparse knowledge I have of things such as these, I have put up a diff file in case you're interested:


Interesting, but using `mocp -i` is really better :)

OT: haven't seen this PasteBin service before, looks very nice.

Damian Pietras - MOC developer

..make OnEvent execution and pass the event name to the script; for example - "play", "pause", "songchange", "stop", "exit" will suite the most needs, I guess.

Sound good, but if there were events that occur often (for example every 1s if such things will be ever needed) it would slow down MOC especially if the script is a perl/java or something that starts up slowly.

Damian Pietras - MOC developer

It`s a funny thing - just as I wanted to emerge myself in writing a patch for mocp to support script executions on song changes, a new version comes.. It'll make me damn lazy :)

But the moment is, that I want to change my Gajim status on song change. So I write a small script which executes gajim-remote, checks the current status, and sets the status-message.

current_status=$( gajim-remote get_status )
exec gajim-remote change_status $current_status "Listening to: \"$1 [$2] - $3\""

The script works perfecly when I execute it myself, from the shell - but when mocp executes it, gajim-remote is not executed from it.

The problem here is not in mocp at all, but in the gajim-remote, which is a bash script itself, which is calling a python script in sequence. By small testing I found out that in the script which is executed by mocp I can perfectly execute any binary, but not a python script.

Is there a way to fix it? (probably, some environment variables must be set, or something)


Thanks for the great work, Damian!

Any error message?

Try adding this after #!/bin/bash:

<br /> set -x<br /> exec >>/tmp/moc_script_debug<br /> exec 2>>/tmp/moc_script_debug<br />

and see if there are any errors in /tmp/moc_script_debug

Damian Pietras - MOC developer

There're lots of error output from gajim-remote it the stdout.
Seems that gajim-remote can not get the address of DBus session - $DBUS_SESSION_BUS_ADDRESS is empty in the script.

I see the problem, try this patch: ftp://ftp.daper.net/pub/soft/moc/patches/moc-2.5.0-alpha1-onsongchange-env.patch

(apply with patch -p0

On my system the DBUS_SESSION_BUS_ADDRESS variable is set only in X terminals, so probably the MOC server must be started from inside X.

Damian Pietras - MOC developer

Compiled with the patch, it works! Thanks a lot!

To get the ol' dopamine flowing, I often play one song over and over again. OnSongChange, however, doesn't activate every time the song has been played---it only activates after the first (or the last...I'm not positive which it is) play of the song.

I'd imagine there's a good reason for this from a programming standpoint, but when it comes to submitting stuff to last.fm through lastfmsubmitd, it means tracks that I might listen to 15 times in a row are only logged once. Is there any possibility that a future version of moc might have OnSongChange activate when a song is repeated?


I would also prefer that OnSongChange is executed every time a song is started, even if it is the same song as before (because of scrobbling via lastfmsubmitd).

Resolved by r2269: Added 'RepeatSongChange' option.

When RepeatSongChange is on, it now also executes the specified command when pausing and resuming a song (even if it is just for a few seconds). That is not the desired behavior imho, as you e.g. want to scrobble the song only if a new song starts (even if it is the same song as before).

You're right, it shouldn't do that.

Fixed and committed to SVN as r2364.