📜 ⬆️ ⬇️

Manage Rhythmbox by ssh

rhythmbox logo

It would seem, what is so difficult. Even rhythmbox itself has a rhythmbox-client satellite program, which takes as an argument simple commands to control this wonderful player. But not everything is as simple as we would like. When ssh is logged on to a remote machine that rhythmbox is playing on and calling this program itself, like this:

user@host:~$ rhythmbox-client --play
(rhythmbox-client:32434): Rhythmbox-WARNING **: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed.

we see not the most pleasant message. At least, we are unable to initialize X11.
And we just wanted to include play in an already running rhythmbox. Although we could do a lot of things, for example:
')
  user @ host: ~ $ rhythmbox-client --help
 Using:
   rhythmbox-client [OPTION ...]

 Options:
   - ?, --help Show help (options)

 Application Options:
   --debug                    
   --no-start Do not start a new copy of rhythmbox
   --quit Exit Rhythmbox
   --no-present Do not represent existing rhythmbox window
   --hide hide rhythmbox window
   --next next song
   --previous previous song
   --notify Show current song notification
   --play Continue playing
   --pause Pause
   --play-pause Switch between pause and play
   --play-uri = URI to play Play the specified URI, import it if necessary
   --enqueue Add track to playlist
   --clear-queue Clear queue playing before adding track
   --print-playing Display the track name and artist name of the current song
   --print-playing-format Display formatted track information.
   --set-volume Set volume (1.0 max)
   --volume-up Increase volume
   --volume-down Volume down
   --print-volume Display current volume
   --mute mute
   --unmute sound on 

As can be seen from the list - the options are not that much. Let's say there is no switch between repeat and random / sequential list of tracks. But this is a basic set of commands, which may well be enough to switch a podnadoevshy track, which you can’t reach to erase your hard drive at all.

If, for the sake of experiment, we connect a virtual X11 with its transfer via ssh, this is done simply by entering a remote host with the -X option. Those. the entire application will be executed on the remote host (host), and X11 primitives will be sent and drawn to you via ssh.

user@localhost:~$ ssh -X user@host

But in this way, too, it’s impossible to control rhythmbox. It just calls a copy of the program, which (with a weak channel) will draw a terribly long time on your computer from which you were doing ssh. Those. the task is to run rhythmbox and then manage it from rhythmbox-client from one X11 display. I know I knew, perhaps, only one way to do this is to run everything through the screen, which will continue to hang, and by going via ssh we can connect to it and control the running rhythmbox. Now, as the respected KeksSW suggested in the comments, you can run the command with the environment variable DISPLAY =: 0, and then the client part will run without any problems and you can really just manage the rhythmbox via ssh without the tricks I continue to write. They may be needed if you decide to simply stuff the management teams into shortcuts.

And so, we will continue.
Having tested all the above plan in the console and making sure that everything works as planned, it is time to direct the beauty. For example, to call an inactive screen session, with a rhythmbox running from it, you need to execute the following command:

user@host:~$ /usr/bin/screen -D -m -S box rhythmbox-client

Two explanations, I indicated a direct path to the screen, since you may have it installed in another place, or if you collected it yourself (... although then I doubt that this publication will be of any interest to you =). And if there is no rhythmbox running, launching the rhythmbox-client will lead to the start of the player itself (at least I had it on Ubuntu 9.04).

Well, do not run the player every time the pens, right? You can write an alias who will do it. But if absolutely lazy, then you can make an icon launcher'a on GNOME'vskoy Ponelke. And then, to launch the player itself, you only need to lazily reach the mouse, lazily move the pointer to the icon, and really quite the last thing just admiring your perseverance and determination - click on it once (the main thing is not to overwork ... Why double click, it's almost twice the work, right?).

launcher


This creates a screen session with the name box , it starts the rhythmbox-client, and deattachitsya the session (it disconnects, to be perfectly accurate, it never joins, and it occurs in passive mode).

Perhaps the easiest way to create an icon on the panel is to drag and drop the rhythmbox icon itself onto the panel from the Applications menu. So you do not have to suffer with the choice of pictures, and it remains only to change the line of the execution code to the one specified above. And we are ready to launch the player in a separate screen session.

Further more interesting trick. We need to go to our host from another computer with rhythmbox running on it and send the command to the screen session, if possible not interactively, and quite the contrary, passively (via pipe or option to screen).

Man screen says that the -X option should send a session command to execute. As I did not get out - I could not do it. So far, the clever comrades on the linux.org forum have not suggested that this option is passed with one more additional argument. For example, if you type:

user@host:~$ screen -r box -X stuff - -

then this text will simply be transmitted to the session, as if you were typing it from the keyboard. But to press the Enter button for you personally will not work. But instead of stuff you can send the option to execute the command. And as not difficult to guess the option will be called exec. Those. in the end, the command to start from the local machine to change the track to the next one on the remote host will be:

user@host:~$ ssh user@host screen -r box -X exec rhythmbox-client --next


And you can also assign this command to any shortcut. I have a set of media keys on the Vostro 1500 on the front panel, which I almost never use on the computer itself, so I decided to hang up the commands I needed on them.

launcher


In principle, this is all. You can only add that if you have not done this before, then allow access to the remote host via ssh without entering a password every time. This can be done as follows:

user@host:~$ ssh-copy-id user@host

You will be prompted for a user password on a remote computer. If you have already generated keys, then the public key will be copied from the local machine to the authorized_keys file on the remote machine. If you get an error about the absence of keys, you can quickly create them:

user@host:~$ ssh-keygen

and further according to the instructions. Passphrase is best not to ask. Since then you have to enter it every time.

That's all. Thanks for attention.

PS: I hope my working computer will pull the load with the return of pictures for the habr. And so that he would do it for good reason, here is a dynamically drawn picture about access to content on the main page and after the habrakat. I know that a couple of days ago one young man was already doing something similar, but I am pursuing my goals, and the graphics, to be honest, were not so hot there. Until the IP filter was turned on, i.e. multiple access counts as different visits. Then I think to add filtering - it will give a better idea of ​​the picture of what is happening.

launcher


ZYY: After three hours spent behind this post, I understand that the only valuable thing in it is a script that draws a picture of the view from the main page of the habr and the number of views from people who still looked under the habrakat. The rating turned out to be not very high, but it also did not jump to the minus. So we get a very good point for statistical analysis. Those. Many of the pictures, the number of requests for which I considered, were received via RSS or simply by quickly browsing the Habr in the morning ... you can get interesting statistics if you collect the same information from the “successful” topic. But this is next time if you're lucky =)

ZYYY: Well, perhaps that's all. The script that draws the statistics of visits brought to the state of betta. Those. it draws the number of requests per minute. As you can see, you can track the entry of the post to the main page, departure to the second page, etc. Great!

Source: https://habr.com/ru/post/74544/


All Articles