wmstartups 8.8 KB

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