Advertisement
metalx1000

BASH Dialog For Desktop Linux and Android

Oct 31st, 2022
1,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.82 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2022  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19. #example of dialog/toaster messages on Desktop Linux and Android
  20. #suggested use it sourcing this file in your scripts
  21. #or pasting it into your code
  22.  
  23. function msg_dialog(){
  24.   title="$1"
  25.   msg="$2"
  26.  
  27.   if [[ `which yad` ]]
  28.   then
  29.     yad --title "$title" --text "$msg"
  30.   elif [[ `which zenity` ]]
  31.   then
  32.     zenity --info --title="$title" --text="$msg"
  33.   elif [[ `which termux-dialog` ]]
  34.   then
  35.     termux-dialog confirm -t "$title" -i "$msg"
  36.   elif [[ `which whiptail` ]]
  37.   then
  38.     whiptail --title "$title" --msgbox "$msg" 8 78
  39.   else
  40.     echo "===$title==="
  41.     echo "$msg"
  42.   fi
  43. }
  44.  
  45. function msg_toaster(){
  46.   title="$1"
  47.   msg="$2"
  48.  
  49.   if [[ `which notify-send` ]]
  50.   then
  51.     notify-send "$title" "$msg"
  52.   elif [[ `which termux-toast` ]]
  53.   then
  54.     termux-toast "$title - $msg"
  55.   else
  56.     echo "==$title=="
  57.     echo "$msg"
  58.   fi
  59. }
  60.  
  61. #example usage - remove after testing
  62. msg_dialog "title message" "This is a test"
  63. msg_toaster "Title Message" "This is a test msg"
  64.  
  65.  
Tags: BASH dialog
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement