wmstartups 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #!/bin/bash
  2. # script to control startup apps that reside in $XDG_CONFIG_HOME/autostart.
  3. # 01micko 131217, ui enhancements by zigbert
  4. # lists
  5. export TEXTDOMAIN=wmstartups
  6. export OUTPUT_CHARSET=UTF-8
  7. . gettext.sh
  8. LIST1=`ls $XDG_CONFIG_HOME/autostart|grep \.desktop$`
  9. LIST2=`ls $XDG_CONFIG_HOME/autostart|grep \.bak$`
  10. export TMP1=/tmp/${RANDOM}1
  11. export TMP2=/tmp/${RANDOM}2
  12. echo -n '' >$TMP1
  13. echo -n '' >$TMP2
  14. #get_enabled
  15. for i in $LIST1
  16. do
  17. ENTRY1=`echo $i|cut -d '.' -f1`
  18. echo "$ENTRY1" >> $TMP1
  19. done
  20. #get_disabled(){
  21. for j in $LIST2
  22. do
  23. ENTRY2=`echo $j|cut -d '.' -f1`
  24. echo "$ENTRY2" >> $TMP2
  25. done
  26. func_sure(){
  27. Xdialog --title "$(gettext 'Startup Apps')" --yesno "$(gettext 'Are you sure you want to delete') \n$1 ?" 0 0
  28. return $?
  29. }
  30. export -f func_sure
  31. #loop used for multiple selections when holding ctrl when clicking
  32. # move to disabled
  33. move_right() {
  34. if [ "$YLIST" != "" ];then
  35. for Y in $YLIST
  36. do
  37. grep -q $Y $TMP2
  38. if [ $? != 0 ];then
  39. /usr/lib/gtkdialog/box_splash -timeout 1 -bg red -text "$(gettext 'Disabling') ${Y} $(gettext 'from startup.')"
  40. echo $Y >> $TMP2
  41. sed -i "/$Y/d" $TMP1
  42. fi
  43. done
  44. fi
  45. return
  46. }
  47. export -f move_right
  48. # move to enabled
  49. move_left() {
  50. if [ "$NLIST" != "" ];then
  51. for N in $NLIST
  52. do
  53. grep -q $N $TMP1
  54. if [ $? != 0 ];then
  55. /usr/lib/gtkdialog/box_splash -timeout 1 -bg green -text "$(gettext 'Enabling') ${N} $(gettext 'at startup.')"
  56. echo $N >> $TMP1
  57. sed -i "/$N/d" $TMP2
  58. fi
  59. done
  60. fi
  61. return
  62. }
  63. export -f move_left
  64. refresh_func() {
  65. YLIST=`cat $TMP1`
  66. NLIST=`cat $TMP2`
  67. }
  68. export -f refresh_func
  69. #delete
  70. del_func(){
  71. if [ "$YLIST" != "" ];then
  72. for D in $YLIST
  73. do
  74. grep -q $D $TMP1
  75. if [ $? = 0 ];then
  76. func_sure $D
  77. if [ "$?" -eq 0 ];then
  78. /usr/lib/gtkdialog/box_splash -timeout 1 -bg red -text "$(gettext 'Deleting') ${D} $(gettext 'from startup.')"
  79. sed -i "/$D/d" $TMP1
  80. [ -f $XDG_CONFIG_HOME/autostart/${D}*.desktop ] && \
  81. rm -f $XDG_CONFIG_HOME/autostart/${D}*.desktop
  82. else
  83. /usr/lib/gtkdialog/box_splash -timeout 1 -text "$(gettext 'Aborting deletion of') ${D}.desktop"
  84. return
  85. fi
  86. else /usr/lib/gtkdialog/box_splash -timeout 1 -bg red -text "$(gettext 'Error in') ${D}.desktop"
  87. return 1
  88. fi
  89. done
  90. /usr/lib/gtkdialog/box_splash -timeout 1 -text "$(gettext 'Successfully deleted') $XDG_CONFIG_HOME/autostart/${D}.desktop"
  91. else /usr/lib/gtkdialog/box_splash -timeout 1 -bg red -text "$(gettext 'Error reading startup list.')"
  92. fi
  93. return
  94. }
  95. export -f del_func
  96. #add
  97. add_func() {
  98. if echo ${Entry1}|grep -q ' ';then
  99. /usr/lib/gtkdialog/box_splash -timeout 3 -bg red -text "${Entry1} $(gettext 'is invalid.')"
  100. else
  101. /usr/lib/gtkdialog/box_splash -timeout 2 -bg green -text "$(gettext 'adding') ${Entry1} $(gettext 'to startup')"
  102. [ "${Entry2}" = "Optional" ] && Entry2=""
  103. [ "${Entry1}" ] && mkautostart "$Entry1" "$Entry2"
  104. grep -q "$Entry1" $TMP1 || echo "$Entry1" >> $TMP1
  105. fi
  106. }
  107. export -f add_func
  108. #run functions to initiate vars
  109. #get_enabled
  110. #get_disabled
  111. refresh_func
  112. # note, using unicode x2212 for minus sign in gui which is a true minus symbol,
  113. # not a dash/hyphen, though it looks the same in geany
  114. export wmStartups='
  115. <window title="'$(gettext "Startup Apps")'" icon-name="gtk-refresh">
  116. <vbox>
  117. '"`/usr/lib/gtkdialog/xml_info fixed startup_app.svg 60 "$(gettext "This applications controls what apps are set to start when X windows starts on your system. These apps include the notification icons in the system tray and some other hidden services that need the graphical server to be running.")"`"'
  118. <notebook labels="'$(gettext 'Enable, Disable or Delete')'|'$(gettext 'Add to Startup')'" space-expand="true" space-fill="true">
  119. <frame '$(gettext "Current Startup Apps")'>
  120. <vbox border-width="10" space-expand="false" space-fill="false">
  121. <text wrap="false" xalign="0" use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext "<b>Remove</b> an app from startup by highlighting in the left pane and pressing <b>−</b>.")'"</label></text>
  122. <text wrap="false" xalign="0" use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext "<b>Add</b> an app to startup by highlighting in the right pane and pressing <b>+</b>.")'"</label></text>
  123. <text wrap="false" xalign="0" use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext "To <b>delete</b> an app, highlight it in the left pane and press the trash icon.")' <b>'$(gettext "Use with caution.")'</b>"</label></text>
  124. </vbox>
  125. <hbox height-request="150" space-fill="true" space-expand="true">
  126. <hbox space-fill="true" space-expand="true">
  127. <tree selection-mode="3">
  128. <variable>YLIST</variable>
  129. <label>'$(gettext "Enabled apps")'</label>
  130. <input>cat '"$TMP1"'</input>
  131. </tree>
  132. </hbox>
  133. <vbox homogeneous="true" space-fill="false" space-expand="false">
  134. <vbox space-fill="false" space-expand="false">
  135. <button border-width="3">
  136. '"`/usr/lib/gtkdialog/xml_button-icon remove`"'
  137. <action>move_right</action>
  138. <action>refresh_func</action>
  139. <action>refresh:YLIST</action>
  140. <action>refresh:NLIST</action>
  141. </button>
  142. <button border-width="3">
  143. '"`/usr/lib/gtkdialog/xml_button-icon add`"'
  144. <action>move_left</action>
  145. <action>refresh_func</action>
  146. <action>refresh:YLIST</action>
  147. <action>refresh:NLIST</action>
  148. </button>
  149. <button border-width="3">
  150. '"`/usr/lib/gtkdialog/xml_button-icon delete`"'
  151. <action>del_func</action>
  152. <action>refresh_func</action>
  153. <action>refresh:YLIST</action>
  154. <action>refresh:NLIST</action>
  155. </button>
  156. </vbox>
  157. </vbox>
  158. <tree selection-mode="3">
  159. <variable>NLIST</variable>
  160. <label>'$(gettext "Disabled apps")'</label>
  161. <input>cat '"$TMP2"'</input>
  162. </tree>
  163. </hbox>
  164. </frame>
  165. <frame '$(gettext "Add Startup Apps")'>
  166. <vbox border-width="10" space-expand="false" space-fill="false">
  167. <text wrap="false" xalign="0" use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext "To add an app to startup type its executable name and press ")'<b>+</b>."</label></text>
  168. <text wrap="false" xalign="0" space-expand="false" space-fill="false"><label>"'$(gettext "Add an optional argument in the second field.")'"</label></text>
  169. <text wrap="false" xalign="0" use-markup="true" space-expand="false" space-fill="false"><label>"<i>'$(gettext "Special Characters need to be escaped with a backslash.")'</i>"</label></text>
  170. </vbox>
  171. <vbox space-expand="false" space-fill="false">
  172. <text space-expand="false" space-fill="false"><label>""</label></text>
  173. <hbox space-fill="true" space-expand="true">
  174. <entry space-fill="true" space-expand="true">
  175. <variable>Entry1</variable>
  176. </entry>
  177. <entry space-fill="true" space-expand="true">
  178. <default>Optional</default>
  179. <variable>Entry2</variable>
  180. </entry>
  181. <button space-expand="false" space-fill="false">
  182. '"`/usr/lib/gtkdialog/xml_button-icon execute_add.svg huge`"'
  183. <action>add_func</action>
  184. <action>refresh_func</action>
  185. <action>refresh:YLIST</action>
  186. <action>refresh:NLIST</action>
  187. </button>
  188. </hbox>
  189. </vbox>
  190. <text space-expand="true" space-fill="true"><label>""</label></text>
  191. </frame>
  192. </notebook>
  193. <hbox space-expand="false" space-fill="false">
  194. <button space-expand="false" space-fill="false">
  195. <label>'$(gettext "Cancel")'</label>
  196. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  197. <action>exit:Cancel</action>
  198. </button>
  199. <button space-expand="false" space-fill="false">
  200. <label>'$(gettext "Ok")'</label>
  201. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  202. <action>exit:OK</action>
  203. </button>
  204. </hbox>
  205. </vbox>
  206. </window>'
  207. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  208. eval $(gtkdialog -p wmStartups)
  209. case $EXIT in
  210. OK)
  211. # these could have been functions in the gtkdialog but no point since once the app closes
  212. # and the user uses an affirmative action [OK] then the processes only need to run once.
  213. # the delete function is different in that it is more powerful hence the warning.
  214. # add to enabled
  215. while read line1; do
  216. [ -f $XDG_CONFIG_HOME/autostart/${line1}.desktop.bak ] && \
  217. mv $XDG_CONFIG_HOME/autostart/${line1}.desktop.bak $XDG_CONFIG_HOME/autostart/${line1}.desktop
  218. done < $TMP1
  219. # add to disabled
  220. while read line2; do
  221. [ -f $XDG_CONFIG_HOME/autostart/${line2}.desktop ] && \
  222. mv $XDG_CONFIG_HOME/autostart/${line2}.desktop $XDG_CONFIG_HOME/autostart/${line2}.desktop.bak
  223. done < $TMP2
  224. rm $TMP1;rm $TMP2;; #cleanup
  225. *)rm $TMP1;rm $TMP2 #cleanup
  226. exit ;;
  227. esac