This makes the coding, running, and debugging cycle quite efficient. There are two main complaints people have with Bash scripts, and the first is speed. There are two kinds of speed, though. You can often knock together a quick script and use it to perform a task much more quickly than developing a solution in a compiled language, such as C.
Nor does it matter for scripts that perform background and batch type processing. There are occasions when you do need something a little more intuitive and modern than the terminal window. Most people are familiar with a graphical user interface GUI.
If you use KDE, you might want to check out kdialog instead, although zenity does run on any desktop environment. The examples in this article show you how to create the different dialog windows from the command line, how to capture their return values and user selections in variables, and how to use the dialog windows in scripts.
A calendar dialog window allows someone to select a date. To create one with zenity requires a single command of two words:. The calendar dialog window appears. You can change the month and year, and click on a day to select that date. Double-clicking a date does the same thing. In the example above, August 19, , is selected. Yes, we achieved the same result in the previous example, but here, we have the selected date stored in a variable.
In the previous example, it was printed and forgotten. Now, the calendar displays our prompt and our window title. We can also customize the format of the date string returned when a selection is made. The --date-format option must be followed by a format specifier. This is a string of tokens that define the data and formats that are to be included in the output.
And the date is returned using our format. It shows the name of the day of the week, followed by the date in European order: day, month, year. File selection dialog windows are quite complex. If you need to use the filename in any further processing, you can capture it in a variable, just as you did for the date from the calendar. If we add one option, we can turn the file selection dialog window into a file save dialog window.
The option is --save. This prompts the person to confirm he wants to overwrite an existing file. The file save dialog window appears. The user can browse to the location of his choice within the file system, provide a name for the file, or click an existing file to overwrite it.
Note the name of the file appears in the warning dialog. The name of the file is stored in the variable Response , which prints to the terminal window. With zenity , including slick notification dialog windows in your scripts is effortless. There are stock dialog windows you can call upon to provide information, warnings, error messages, and questions for the user.
It holds the return value from the most recently executed foreground pipeline. In general terms, this is the value from the most recently closed process. This is a general technique you can apply to any of the zenity dialog windows. Active Oldest Votes. Improve this answer. Hey thanks for solving this problem.. Can i ask one more question.
Eka I don't know zenity but in any case, please ask new questions by posting a new Question. Eka my last example shows how to get the number of words alone.
I think that the correct code may be this:! Do you want to select one? Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Yad looks quite good - it has more options than zenity : — Wilf.
Wilf Yes, yad is Zenity on steroids. Once you get to grips with it, it rocks as it's so flexible. I am a convert. I yadded couldn't resist that, sorry a response to the OPs question below, btw. Scooby-2 cool added install instructions to answer so future users don't have to do comments — Wilf.
Show 3 more comments. Though it is right alternative solution but it doesn't provide GUI window as mentioned in question! I know, but someone else might find it useful. I posted the screenshot to avoid any confusion. Scooby-2 Scooby-2 1 1 gold badge 6 6 silver badges 15 15 bronze badges. Add a comment. Here is the shortest and best solution to the answer: Yad provides the exact option just like zenity does: yad --file-selection --directory This opens a directory selection dialog.
TheUnseen TheUnseen 41 2 2 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Helping communities build their own LTE networks. Podcast Making Agile work for data science. Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.
Linked 0. Related 0. Hot Network Questions.
0コメント