Need a script to autopause clementine on skype call

I am a linux user (PcLinuxOs desktop 64bit kde5). I am looking for a script (bash or python) to autopause clementine (a music player) on skype call. VLC works: autopause on skype call and at the end resume). Clementine automute, but not autopause, on skype call.
I am absolute beginner with the scripts, so I need your help.
Bash comman to pause clementine is "clementine --pause", but witch command for "if" or "when" or "while"?

Thank you
Duns

I believe that under Skype settings -> Notifications you can execute a script on a number of events, why not create a script to do clementine --pause under the incoming call Notification:

1 Like

Thank you very much

Your help solved the bulk of the problem, but remain some things to perfect, i.e. how don't start clementine if before the skype call was stopped. How i.e. resume only if paused and not if stopped.
Now I put this script after the call:

#!/bin/bash
if pgrep -x "clementine" > /dev/null
then
    clementine --play
fi

Could you help me (another bash script)?
Tried with fg, but don't works.

In what way does it not work? What happens? What do you want to happen? What were you expecting fg to do? I don't understand its use here.

Clementine paused is not seen as a job suspended, so I get a error message:

$ fg %clementine
bash: fg: %clementine: no such job

.
I want resume music paused, if paused and do nothing if stopped.

Oh, you want it to do nothing if the music is stopped. OK. You'll need to ask clementine whether it's paused or not somehow. That's not something pgrep or fg can tell you, since clementine isn't actually "stopped" in a program sense, just a "not playing" sense.

Does clementine show any status information? I don't have any way to test it on this end.

So, do you think that there is a solution?

Depends, does clementine print any status information? I can't tell.

I found this script to get clementine status: https://groups.google.com/forum/#!topic/clementine-player/uTuuZaN_taY.
But I'm not a developer, it's complicated for me :frowning:

Oh, that digs deep into /proc/ to figure out if clementine has an audio device open. If they're going to those desperate lengths, then no, Clementine does not print status information. But maybe we can work with that.

PID=$(pgrep -x "clementine")

[ -z "$PID" ] && exit # Skip if Clementine's not running

if ls -l /proc/$PID/fd | egrep -q 'audio|video'
then
        # clementine is playing or paused
        clementine -t
fi

This depends on the names of the device files though. If you could show what ls -l /proc/clementinepid/fd/ really looks like during playback, during pause, and when stopped, that would help.

1 Like

Error message:

$ ls -l /proc/clementinepid/fd/
ls: cannot access /proc/clementinepid/fd/: No such file or directory

Searching in /proc: no file o folder naming clementine, even the program is open and running.

I don't literally mean 'clementinepid'. I mean, clementine's PID. It's the number printed by 'pgrep -x clementine'.

1 Like

When paused:

$ ls -l /proc/7070/fd/
total 0
lr-x------ 1 duns duns 64 feb  8 17:31 0 -> pipe:[452182]
l-wx------ 1 duns duns 64 feb  8 17:31 1 -> pipe:[10435]
l-wx------ 1 duns duns 64 feb  8 17:31 2 -> pipe:[10436]
lrwx------ 1 duns duns 64 feb  8 17:31 27 -> socket:[212703]
lrwx------ 1 duns duns 64 feb  8 17:31 3 -> anon_inode:[eventfd]
lrwx------ 1 duns duns 64 feb  8 17:31 33 -> socket:[212704]
lr-x------ 1 duns duns 64 feb  8 17:31 4 -> pipe:[452189]
l-wx------ 1 duns duns 64 feb  8 17:31 5 -> pipe:[452189]
lrwx------ 1 duns duns 64 feb  8 17:31 6 -> socket:[452190]
[duns@localhost ~]$ 

When playing:

$ ls -l /proc/7070/fd/
total 0
lr-x------ 1 duns duns 64 feb  8 17:31 0 -> pipe:[452182]
l-wx------ 1 duns duns 64 feb  8 17:31 1 -> pipe:[10435]
l-wx------ 1 duns duns 64 feb  8 17:31 2 -> pipe:[10436]
lrwx------ 1 duns duns 64 feb  8 17:31 27 -> socket:[212703]
lrwx------ 1 duns duns 64 feb  8 17:31 3 -> anon_inode:[eventfd]
lrwx------ 1 duns duns 64 feb  8 17:31 33 -> socket:[212704]
lr-x------ 1 duns duns 64 feb  8 17:31 4 -> pipe:[452189]
l-wx------ 1 duns duns 64 feb  8 17:31 5 -> pipe:[452189]
lrwx------ 1 duns duns 64 feb  8 17:31 6 -> socket:[452190]

When stopped:

$ ls -l /proc/7070/fd/
total 0
lr-x------ 1 duns duns 64 feb  8 17:31 0 -> pipe:[452182]
l-wx------ 1 duns duns 64 feb  8 17:31 1 -> pipe:[10435]
l-wx------ 1 duns duns 64 feb  8 17:31 2 -> pipe:[10436]
lrwx------ 1 duns duns 64 feb  8 17:31 27 -> socket:[212703]
lrwx------ 1 duns duns 64 feb  8 17:31 3 -> anon_inode:[eventfd]
lrwx------ 1 duns duns 64 feb  8 17:31 33 -> socket:[212704]
lr-x------ 1 duns duns 64 feb  8 17:31 4 -> pipe:[452189]
l-wx------ 1 duns duns 64 feb  8 17:31 5 -> pipe:[452189]
lrwx------ 1 duns duns 64 feb  8 17:31 6 -> socket:[452190]

That's not going to work for your purposes. Sorry. It's not connecting to any devices, must be using a daemon.

The best I can suggest is check if it's running, and pause it if it is, for you to unpause yourself after.

1 Like

This script solved all:

#!/bin/bash
#Written by Matthew Headlee 20170208

#Send all output to null, comment out for debugging.
exec &> /dev/null

#Function eClementineGetState() checks current state of media playback
#returns 0 if media is playing, 1 if paused, 2 if stopped, 3 if not running
eClementineGetState() {
    iClemPID=$(pgrep -x clementine)
    if [ ! -z "${iClemPID}" ]; then
        for sFileDes in $(find /proc/${iClemPID}/fd -type l); do
            if file -bi "$(readlink -f ${sFileDes})" | awk '!/video|audio/ {exit 1}'; then
                #echo "Playing or Paused."
                echo "Media File Handle is ${sFileDes}"

                sFileDesInfo="/proc/${iClemPID}/fdinfo/$(basename ${sFileDes})"
                iFilePosA=$(awk '/pos:/ {print $2}' "${sFileDesInfo}")
                sleep .1
                iFilePosB=$(awk '/pos:/ {print $2}' "${sFileDesInfo}")
                if [ "${iFilePosA}" -ne "${iFilePosB}" ]; then
                    echo "Playing."
                    return 0
                fi

                echo "Paused."
                return 1
            fi
        done
        echo "Stopped."
        return 2
    fi
    echo "Media Player Not Found."
    return 3
}

eClementineGetState
[ "${?}" -eq 1 ] && clementine --play

Clementine resume the music only if before paused.

1 Like

I admit I don't know how it could possibly work! But I'm glad it works for you.

1 Like

with skype 5 for linux you can still enable scripts for certain events? I do not see how ...:mad: