How to Handle Window Titles with Spaces in mpv Command Line?

0
14
Asked By CuriousCoder99 On

I'm having some trouble when trying to get a window title into the command line for mpv if that title contains spaces. No matter what I try—like using single quotes or backslashes—it only grabs the text before the first space. The best workaround I've found is substituting spaces with the "En Quad" character, but I'd prefer to find a proper solution. I want to understand how to do this to avoid issues in the future, especially since the script I'm working on involves more complex logic than this test example. Here's the shell script I've been working with, although Reddit's formatting messed it up a bit:

3 Answers

Answered By ScriptingSavvy21 On

It’s actually much easier if you use arrays instead of string concatenation. You can condense your whole script into just a few lines like this:
```bash
command_line=(mpv)
command_line+=(--idle)
command_line+=(--force-window)
command_line+=(--title="${window_title}")

"${command_line[@]}"
```

Answered By SyntaxGuru77 On

The bot mentioned formatting issues with the shell script. Make sure to use four spaces before each line for code blocks for better clarity in your posts.

Answered By OldSchoolScripter On

Just for context, if it helps, I've been in similar spots, and while the complexities can pile up, tackling them one by one tends to yield the best progress. Keep honing that script!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.