2

Chances are that the title makes absolutely no sense as I'm still a total newbie to linux in general, but basically what I'm trying to do is make a keyboard shortcut which would instantly make mpv play an url from my clipboard when I press Win+M.

I'm obviously totally misunderstanding how this works, as reading about piping I had gotten the idea that I'd have to use piping and tried things like xclip | mpv and xclip -o | mpv while having a youtube url on my clipboard, like https://www.youtube.com/watch?v=KqI6TOlPluo for an example, but it seems to just come up with the same stuff as if I only wrote mpv with nothing else in the terminal. If somebody could clear up whether this is even possible would be really nice, Ubuntu seems like it'd be great if I learnt to use it a little better.

edit: As clarification, I want the result to be the same as just doing mpv https://www.youtube.com/watch?v=KqI6TOlPluo

Aaron
  • 23
  • 3
  • https://askubuntu.com/questions/1036847/launching-mpv-from-a-desktop-entry-with-the-clipboard-as-argument – DK Bose Oct 23 '18 at 13:34

1 Answers1

4

You have to use command sub situation:

mpv "$(xclip -o -selection clipboard)"

or for primary x selection:

mpv "$(xclip -o -selection primary)"

Lets say your clipboard contains http://example.foo/video.mp4, the result would be:

mpv "http://example.foo/video.mp4"

What you are doing is piping stdout of your first command which is the url, to the stdin of second command "mpv" which doesn't look for anything from stdin and even if it does (e.g: mpv -) it looks for data to play and not a url or file address.

Ravexina
  • 54,268
  • 25
  • 157
  • 179
  • OP might want `xclip -o -selection clipboard`, as the default is the middle-click clipboard. – pLumo Oct 23 '18 at 13:39
  • Ahh, thanks a lot, this works perfectly. Much needed to make my life easier, because I'm on a netbook that can't even run youtube videos properly, but mpv seems to run them perfectly. Looks like I should probably look into some linux tutorials a bit more so I don't get stuff like this mixed up. – Aaron Oct 23 '18 at 13:40
  • @Aaron you're welcome... you can accept the answer by clicking on the gray tick if you think it was helpful to you. – Ravexina Oct 23 '18 at 13:43
  • @RoVo Updated the answer ... ;) – Ravexina Oct 23 '18 at 13:45