5

Im pretty new to zenity and bash. Im trying to make file selection window that will display only the ones with .ogg, .aac and .wav extension. I tried this, but it doesn't work.

option=`zenity --file-selection --file-filter=*.ogg | *.aac`

For one extension it's working as intented:

option=`zenity --file-selection --file-filter=*.ogg`

Zenity man provides information:

--file-filter=NAME | PATTERN1 PATTERN2
Sets a filename filter

I dont really understand how am I supposed to use it. Can someone show me some examples?

  • I haven't zenity, so only guessing. So, try this: `--file-filter="*.ogg|*.aac"` – clt60 Apr 28 '13 at 20:13
  • Yeah, thansk for the effort :) This one gives only the ones that ends on .aac. –  Apr 28 '13 at 20:24

2 Answers2

8

Special bash symbols | and * needs escaping (backslash) or quoting (single or double), and you have succeeded with that. With single quotes the argument is passed literally to zenity.

Repeat the --file-filter option if you want more filter choices For example, you may want two filters "All files" and "Music files" in the file selection window:

zenity --file-selection --file-filter='Music files (ogg,wav,aac) | *.ogg *.wav *.aac' --file-filter='All files | *'
BFruit
  • 81
  • 1
  • 1
  • 1
    Until I saw this post, I had not tried multiple, separate `--file-filter="Filetype | *.foo"` flags. It hadn't even occurred to me! They should update their documentation. – bgStack15 Feb 02 '17 at 20:46
  • The updated documentation can be found in https://manpages.ubuntu.com/manpages/lunar/en/man1/zenity.1.html – Ahmad Ismail Jun 20 '23 at 00:59
5

Ok I found the solution, maybe someone will use it in the future:

zenity --file-selection --file-filter=""*.ogg" "*.wav" "*.aac""
  • 2
    And indeed it is helpful in the future. Thanks! – Thunderforge May 25 '13 at 04:05
  • Thanks for posting the answer, I don't think I would have figured that out on my own. But now that you pointed me in the right direction, I found how to do descriptions and multiple dropdown options too - hope you don't mind the edit :) – Jason O'Neil Jul 01 '13 at 09:30
  • 2
    Those quotes are mostly unnecessary. Just use `"*.ogg *.wav *.aac"`. – rich remer Oct 09 '17 at 18:52
  • It seems as if the quotes are interpreted by Bash and not zenity - this means that it works for you by luck because the files in the current directory are used as a filter. – Doron Behar Jun 15 '20 at 19:45