Advertisement
clockworkpc

Ubuntu Tweaks for Natty Narwhal

May 7th, 2011
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.31 KB | None | 0 0
  1. #!/usr/bin/python
  2. #/home/clockworkpc/Documents/bin/natty_tweaks.py
  3.  
  4. # Released under a GPLv3 Licence by Clockwork PC 2011  
  5. #
  6. # www.clockworkpc.com.au
  7. #
  8. # You are entitled to the following four freedoms:
  9. # Freedom 0: To run this program for any purpose
  10. # Freedom 1: To study how this program works and change it to make it do what you wish
  11. # Freedom 2: To redistribute copies so you can help your neighbour
  12. # Freedom 3: To distribute copies of your modified version to others
  13.  
  14. # This script covers two operations:
  15. # (1) Moving the main home folders to /media/DATA/Users/Dropbox so that data on Ubuntu can be shared with Mac seamlessly
  16. # (2) Apply a variety of tweaks to make Unity more functional
  17.  
  18. import os
  19. import time
  20.  
  21. home = os.getenv("HOME")+'/'
  22. user_dirs = home+'.config/user-dirs.dirs'
  23. gtk_bookmarks = home+'.gtk-bookmarks'
  24. data_partition = '/media/DATA/Users/Dropbox/' #Please make sure this is where you want to put your Documents, Downloads, Music Pictures, and Videos.  
  25.  
  26. #NOTE: I DO NOT move the Desktop folder, because it seems to cause problems -- not to mention sharing your desktop with another OS can get messy, especially if it's a retarded one like OSX on Windows, which saves EVERYTHING to the Desktop.
  27.  
  28. #Copy the contents of the existing user folders into the Dropbox folder on the DATA partition.  Not strictly necessary if you run this on a vanilla installation, but still worthwhile.
  29.  
  30. os.system("cp --recursive --no-clobber --dereference --verbose $HOME/Documents /media/DATA/Users/Dropbox/")
  31. os.system("cp --recursive --no-clobber --dereference --verbose $HOME/Downloads /media/DATA/Users/Dropbox/")
  32. os.system("cp --recursive --no-clobber --dereference --verbose $HOME/Music /media/DATA/Users/Dropbox/")
  33. os.system("cp --recursive --no-clobber --dereference --verbose $HOME/Pictures /media/DATA/Users/Dropbox/")
  34. os.system("cp --recursive --no-clobber --dereference --verbose $HOME/Videos /media/DATA/Users/Dropbox/")
  35. os.system("cp --recursive --no-clobber --dereference --verbose $HOME/Templates /media/DATA/Users/Dropbox/")
  36. os.system("cp --recursive --no-clobber --dereference --verbose $HOME/Public /media/DATA/Users/Dropbox/")
  37.  
  38. print "The key directories are as follows:"
  39. print home
  40. print user_dirs
  41. print gtk_bookmarks
  42. print data_partition
  43.  
  44. time.sleep(3)
  45.  
  46. print """
  47. You have 5 seconds to press ctrl+C to abort this operation if something is amiss.
  48. """
  49.  
  50. time.sleep(5)
  51.  
  52. #Back up the User Directories list in case all hell breaks loose.
  53.  
  54. os.system("cp $HOME/.config/user-dirs.dirs $HOME/.config/user-dirs.dirs.$(date +%F_%A_at_%H:%M:%S).backup ")
  55.  
  56. #Over-write the User Directories listing in ~/.config/user-dirs.dirs with the new location, presumably on the data partition
  57.  
  58. f=open(user_dirs,w)
  59. f.write('''
  60. XDG_PUBLICSHARE_DIR="/media/DATA/Users/Dropbox/Public"
  61. XDG_DOWNLOAD_DIR="/media/DATA/Users/Dropbox/Downloads"
  62. XDG_MUSIC_DIR="/media/DATA/Users/Dropbox/Music"
  63. XDG_VIDEOS_DIR="/media/DATA/Users/Dropbox/Videos"
  64. XDG_DESKTOP_DIR="$HOME/Desktop"
  65. XDG_DOCUMENTS_DIR="/media/DATA/Users/Dropbox/Documents"
  66. XDG_TEMPLATES_DIR="/media/DATA/Users/Dropbox/Templates"
  67. XDG_PICTURES_DIR="/media/DATA/Users/Dropbox/Pictures"
  68. ''')
  69. f.close()
  70.  
  71. #Back up the GTK Bookmarks in case all hell breaks loose.
  72.  
  73. os.system("cp $HOME/.gtk-bookmarks $HOME/gtk-bookmarks.$(date +%F_%A_at_%H:%M:%S).backup")
  74.  
  75. #Over-write the GTK Bookmark (~/.gtk-bookmarks) with the new location, presumably on the data partition
  76.  
  77. g=open(gtk_bookmarks)
  78. g.write('''
  79. file:///media/DATA/Users/Dropbox/Documents
  80. file:///media/DATA/Users/Dropbox/Music
  81. file:///media/DATA/Users/Dropbox/Pictures
  82. file:///media/DATA/Users/Dropbox/Videos
  83. file:///media/DATA/Users/Dropbox/Downloads
  84. file:///media/DATA/Websites
  85. file:///media/DATA/Screenshots
  86. file:///media/DATA/ISO
  87. ''')
  88. g.close()
  89.  
  90. #Delete the existing User folders so that they can be replaced with symbolic links
  91.  
  92. os.system("rm -rv $HOME/Documents")
  93. os.system("rm -rv $HOME/Music")
  94. os.system("rm -rv $HOME/Pictures")
  95. os.system("rm -rv $HOME/Videos")
  96. os.system("rm -rv $HOME/Downloads")
  97. os.system("rm -rv $HOME/Public")
  98. os.system("rm -rv $HOME/Templates")
  99.  
  100. # Replace newly deleted User folders with symbolic links to the folders in your specified location, presumably at /media/DATA/Users/Dropbox
  101.  
  102. os.system(" $HOME && ln -s /media/DATA/Documents")
  103. os.system(" $HOME && ln -s /media/DATA/Downloads ")
  104. os.system(" $HOME && ln -s /media/DATA/Music")
  105. os.system(" $HOME && ln -s /media/DATA/Pictures")
  106. os.system(" $HOME && ln -s /media/DATA/Videos")
  107. os.system(" $HOME && ln -s /media/DATA/Public")
  108. os.system(" $HOME && ln -s /media/DATA/Templates")
  109.  
  110. ### UNITY TWEAKS (Hooray!)
  111.  
  112. #!/usr/bin/python
  113. #/home/clockworkpc/Documents/bin/test_unity_tweaks.py
  114.  
  115. # Released under a GPLv3 Licence by Clockwork PC 2011  
  116. #
  117. # www.clockworkpc.com.au
  118. #
  119. # You are entitled to the following four freedoms:
  120. # Freedom 0: To run this program for any purpose
  121. # Freedom 1: To study how this program works and change it to make it do what you wish
  122. # Freedom 2: To redistribute copies so you can help your neighbour
  123. # Freedom 3: To distribute copies of your modified version to others
  124.  
  125. import os
  126. import fileinput
  127.  
  128. home=os.getenv("HOME")+"/"
  129.  
  130. # Home Folders Quicklist
  131.  
  132. os.system("cp /usr/share/applications/nautilus-home.desktop ~/.local/share/applications")
  133. nautilus_home=home+".local/share/applications/nautilus-home.desktop"
  134.  
  135. f=open(nautilus_home, "w")
  136. f.write(''''[Desktop Entry]
  137.  
  138. Name=Home Folder
  139. Comment=Open your personal folder
  140. TryExec=nautilus
  141. Exec=nautilus --no-desktop
  142. Icon=user-home
  143. Terminal=false
  144. StartupNotify=true
  145. Type=Application
  146. Categories=GNOME;GTK;Core;
  147. OnlyShowIn=GNOME;Unity;
  148. X-GNOME-Bugzilla-Bugzilla=GNOME
  149. X-GNOME-Bugzilla-Product=nautilus
  150. X-GNOME-Bugzilla-Component=general
  151. X-Ubuntu-Gettext-Domain=nautilus
  152.  
  153. X-Ayatana-Desktop-Shortcuts=Videos;Documents;Music;Pictures;Downloads
  154. [Videos Shortcut Group]
  155. Name=Videos
  156. Exec=nautilus Videos
  157. TargetEnvironment=Unity
  158.  
  159.  
  160. [Documents Shortcut Group]
  161. Name=Documents
  162. Exec=nautilus Documents
  163. TargetEnvironment=Unity
  164.  
  165. [Music Shortcut Group]
  166. Name=Music
  167. Exec=nautilus Music
  168. TargetEnvironment=Unity
  169.  
  170. [Pictures Shortcut Group]
  171. Name=Pictures
  172. Exec=nautilus Pictures
  173. TargetEnvironment=Unity
  174.  
  175. [Downloads Shortcut Group]
  176. Name=Downloads
  177. Exec=nautilus Downloads
  178. TargetEnvironment=Unity
  179. ''')
  180. f.close()
  181.  
  182. # Ubuntu Software Centre Quicklist
  183.  
  184. os.system("cp /usr/share/applications/ubuntu-software-center.desktop ~/.local/share/applications/")
  185. usc = home+".local/share/applications/ubuntu-software-center.desktop"
  186.  
  187. g = open(usc, "w")
  188. g.write(''''X-Ayatana-Desktop-Shortcuts=SoftwareProperties;SoftwareSources;
  189.  
  190. [SoftwareProperties Shortcut Group]
  191. Name=Update Manager
  192. Exec=update-manager -c %u
  193. TargetEnvironment=Unity
  194.  
  195. [SoftwareSources Shortcut Group]
  196. Name=Add/Edit PPAs
  197. Exec=gksu software-properties-gtk
  198. TargetEnvironment=Unity
  199.  
  200. ''')
  201. g.close()
  202.  
  203. # Chromium Quicklist
  204.  
  205. os.system ("cp /usr/share/applications/chromium-browser.desktop ~/.local/share/applications")
  206. chromium = home+".local/share/applications/chromium-browser.desktop"
  207.  
  208. h=open(chromium, "w")
  209. h.write('''X-Ayatana-Desktop-Shortcuts=NewWindow;Incognito;
  210.  
  211. [NewWindow Shortcut Group]
  212. Name=New Window
  213. Exec=chromium-browser
  214. TargetEnvironment=Unity
  215.  
  216. [Incognito Shortcut Group]
  217. Name=New incognito window
  218. Exec=chromium-browser --incognito
  219. TargetEnvironment=Unity
  220. ''')
  221. h.close()
  222.  
  223. # Terminal Quicklist
  224.  
  225. import re
  226.  
  227. os.system ("cp /usr/share/applications/gnome-terminal.desktop ~/.local/share/applications")
  228.  
  229. gt=home+".local/share/applications/gnome-terminal.desktop"
  230.  
  231. x = fileinput.input(gt, inplace=1)
  232. for line in x:
  233.     line = line.replace("OnlyShowIn=GNOME;", "OnlyShowIn=GNOME;Unity;")
  234.     print line,
  235. x.close()
  236.  
  237. k=open(gt, "a")
  238. k.write('''X-Ayatana-Desktop-Shortcuts=NewWindow;NewTab;Top;Root;
  239.  
  240. [NewWindow Shortcut Group]
  241. Name=New Window
  242. Exec=gnome-terminal --window
  243. TargetEnvironment=Unity
  244.  
  245. [NewTab Shortcut Group]
  246. Name=New Tab
  247. Exec=gnome-terminal --tab
  248. TargetEnvironment=Unity
  249.  
  250. [Root Shortcut Group]
  251. Name=Root Terminal
  252. Exec=gksudo gnome-terminal
  253. TargetEnvironment=Unity
  254.  
  255. [Top Shortcut Group]
  256. Name=Top
  257. Exec=gnome-terminal --command top
  258. TargetEnvironment=Unity
  259. ''')
  260. k.close()
  261.  
  262. # LibreOffice Quicklist
  263.  
  264. os.system('cp /usr/share/applications/libreoffice-startcenter.desktop ~/.local/share/applications')
  265. LibreOffice = home+"/.local/share/applications/libreoffice-startcenter.desktop"
  266.  
  267. l=open(LibreOffice, "w")
  268. l.write('''##Start of shortcut menu
  269. ##List of shortcuts
  270. X-Ayatana-Desktop-Shortcuts=Writer;Impress;Calc;Math;Draw
  271.  
  272. ##Define Shortcuts
  273. [Writer Shortcut Group]
  274. Name=Writer
  275. Exec=libreoffice -writer %U
  276. TargetEnvironment=Unity
  277.  
  278. [Impress Shortcut Group]
  279. Name=Impress
  280. Exec=libreoffice -impress %U
  281. TargetEnvironment=Unity
  282.  
  283. [Calc Shortcut Group]
  284. Name=Calc
  285. Exec=libreoffice -calc %U
  286. TargetEnvironment=Unity
  287.  
  288. [Math Shortcut Group]
  289. Name=Math
  290. Exec=libreoffice -math %U
  291. TargetEnvironment=Unity
  292.  
  293. [Draw Shortcut Group]
  294. Name=Draw
  295. Exec=libreoffice -draw %U
  296. TargetEnvironment=Unity
  297. ##End of shortcut menu
  298. ''')
  299. l.close()
  300.  
  301. # Apply the changes
  302. os.system("unity --replace")
  303.  
  304. os.system("gedit ~/.local/share/applications/nautilus-home.desktop ~/.local/share/applications/ubuntu-software-center.desktop ~/.local/share/applications/chromium-browser.desktop ~/.local/share/applications/gnome-terminal.desktop ~/.local/share/applications/libreoffice-startcenter.desktop")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement