BASH - file selection by multiple patterns in zenity
Asked Answered
A

2

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?

Azazel answered 28/4, 2013 at 19:44 Comment(2)
I haven't zenity, so only guessing. So, try this: --file-filter="*.ogg|*.aac"Counterpressure
Yeah, thansk for the effort :) This one gives only the ones that ends on .aac.Azazel
A
5

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

zenity --file-selection --file-filter=""*.ogg" "*.wav" "*.aac""
Azazel answered 28/4, 2013 at 20:55 Comment(4)
And indeed it is helpful in the future. Thanks!Pastypat
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 :)Monochromat
Those quotes are mostly unnecessary. Just use "*.ogg *.wav *.aac".Incontrollable
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.Buke
W
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 | *'
Westwardly answered 9/2, 2014 at 18:41 Comment(2)
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.Barstow
The updated documentation can be found in manpages.ubuntu.com/manpages/lunar/en/man1/zenity.1.htmlFreemason
A
5

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

zenity --file-selection --file-filter=""*.ogg" "*.wav" "*.aac""
Azazel answered 28/4, 2013 at 20:55 Comment(4)
And indeed it is helpful in the future. Thanks!Pastypat
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 :)Monochromat
Those quotes are mostly unnecessary. Just use "*.ogg *.wav *.aac".Incontrollable
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.Buke

© 2022 - 2024 — McMap. All rights reserved.