Advertisement
applehelpwriter

FastTasks

Dec 1st, 2012
1,508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.93 KB | None | 0 0
  1. #! /bin/bash
  2. #FastTasks by Applehelpwriter.com, 2012.
  3. #Version 1.2
  4.  
  5. #changelog
  6. #version 1.2: added confirmation msg upon success for options 8 & 9
  7.  
  8. # Requirements:
  9. # Needs OS X 10.8, Mountain Lion, but should work on 10.7
  10. # Menu option 8 won't work on 10.6 or earlier
  11.  
  12. # This script lets you perform 10 common tasks from one menu
  13. # 1. Reveal hidden files in Finder
  14. # 2. Hide hidden files in Finder
  15. # 3. Open the User Library in Finder
  16. # 4. Open the User Library Preferences folder in Finder
  17. # 5. Kill and Relaunch the Finder
  18. # 6. Kill and Relaunch the Dock
  19. # 7. Reset System Preferences to Default (requires restart)...
  20. # 8. Flush DNS Cache (requires Admin password)
  21. # 9. Free system memory (purge)"
  22. # 10. Batch change file extension
  23.  
  24. #HOW TO USE
  25.  
  26. # Step 1
  27. # Create a plain text file in text edit and copy the
  28. # entire contents of this file, including these comments, into it.
  29. # Save the script to your desktop as 'FastTasks' without the quote marks
  30. # make sure that it's saved as plain text, not RTF.
  31.  
  32. # Step 2
  33. # Open Terminal.app and paste the following line without the '#'
  34.  
  35. # sudo chmod 755 ~/Desktop/FastTasks
  36.  
  37. # press 'return' on your keyboard
  38. # enter your Admin user password to authorise the change
  39. # - what you just did is turn the plain text script into an
  40. # executable program file.
  41.  
  42. # Step 3
  43. # Now let's copy the script to somewhere where Bash looks for programs.
  44. # Paste the next line without the # into Terminal.app
  45.  
  46. # cp ~/Desktop/FastTasks /etc/bin/FastTasks
  47.  
  48. # then press 'return' on your keyboard.
  49.  
  50. # Step 4
  51. # Now you can use the script by typing 'FastTasks' in a
  52. # Terminal window or you can run FastTasks by double-clicking
  53. # it in Finder or on the Desktop.
  54. # If the Terminal window remains open after FastTasks has
  55. # completed, change the following settings
  56. # in Terminal's Preferences:
  57.  
  58. # Preferences > Settings > Shell > When the shell exits...
  59.  
  60. # Change the drop down menu from 'Don't close the window' to
  61. # 'Close if the shell exited cleanly'.
  62.  
  63. # END OF NOTES
  64.  
  65.  
  66. # START OF SCRIPT
  67. # Define the function for batch file extension changes
  68.  
  69. function rename_files
  70. {
  71. clear; echo ""
  72.     echo "**** Change file extension ****"
  73.     echo "This utility allows you to change multiple files with one extension"
  74.     echo "to another extension"
  75.     echo "(e.g., change a list of jpg files to tiffs)"
  76.     echo ""
  77.     echo "PREPARATION:"
  78.     echo "Before proceeding, place the files you want to change on the Desktop."
  79.     echo "Ensure there are no other files with the same extension on the Desktop."
  80.     echo ""
  81.     echo "Are the files you want to change on the Desktop?"
  82.     echo -n "Press 1 for 'yes' or Press 2 for 'no'  "
  83.     read text
  84.     if [ "$text" = "1" ]; then
  85.         clear;
  86.         echo "Enter the old file extension or press Ctrl-C to cancel"
  87.         echo -n "(do not include the dot before the extension)... "
  88.         read oldex
  89.         echo "Enter the new file extension or press Ctrl-C to cancel"
  90.         echo -n "(do not include the dot before the extension)... "
  91.         read newex
  92.         echo "Confirm Change $oldex to $newex?"
  93.         echo -n "(press 'enter' to confirm, Ctl-C to escape)"
  94.         read
  95. # command to perform the batch change  
  96.         cd ~/desktop; for i in *.$oldex; do mv "$i" "${i/.$oldex}".$newex; done
  97.             #echo "Your files have been successfully changed."
  98.             #else echo "Sorry no files were changed."
  99.             #fi
  100.     else echo "Please move the files to the Desktop before trying again. Thank you."
  101. fi
  102. }
  103.  
  104. # define function for changing sys prefs to default
  105. # useful if you have problems with system preferences
  106.  
  107. function sysprefs_to_default
  108. {
  109. clear;
  110. echo "**** Return System Preferences to default values ****"
  111. echo ""
  112. echo "This utility can help solve problems such as System Preference panes not opening"
  113. echo "or only opening after a lengthy spin of the pinwheel..."
  114. echo ""
  115. echo "This utility is harmless, but it will return all your system preferences back"
  116. echo "to default, so you may have to set some system pref choices up again."
  117. echo ""
  118. echo "WARNING - save any unsaved work in open apps before proceeding."
  119. echo ""
  120. echo -n "Press enter to reset System Prefs or Ctl-C to cancel..."
  121. read
  122. rm ~/Library/Preferences/com.apple.systempreferences.plist; clear;
  123. echo "You must restart your mac to complete the change to default preferences."
  124. echo ""
  125. echo "1 = quit FastTasks and shutdown manually"
  126. echo "(choose this if you have unsaved work in open Apps)"
  127. echo ""
  128. echo "2 = quit FastTasks and restart IMMEDIATELY"
  129. echo "(requires Admin password - you could lose any unsaved work)"
  130. echo -n "Enter 1 or 2..."
  131. read answer
  132. case $answer in
  133.     1 ) exit=0
  134.     ;; 
  135.     2 ) sudo shutdown -r now
  136.     ;;
  137.     * ) exit =0
  138. esac
  139. }
  140.  
  141.  
  142. # Text for the user menu options:
  143.  
  144. clear;
  145. echo "MENU:"
  146. echo "1  = Reveal hidden files in Finder"
  147. echo "2  = Hide hidden files in Finder"
  148. echo ""
  149. echo "3  = Open the User Library in Finder"
  150. echo "4  = Open the User Library Preferences folder in Finder"
  151. echo ""
  152. echo "5  = Kill and Relaunch the Finder"
  153. echo "6  = Kill and Relaunch the Dock"
  154. echo ""
  155. echo "7  = Reset System Preferences to Default (requires restart)..."
  156. echo ""
  157. echo "8  = Flush DNS Cache (requires Admin password)"
  158. echo "9  = Free system memory (purge)"
  159. echo ""
  160. echo "10 = Batch change file extension..."
  161. echo ""
  162. echo "or press 0 = Exit FastTasks"
  163. echo ""
  164.  
  165. # Get the user's choice
  166.  
  167. echo -n "Enter a number between 0 and 10: "
  168. read character
  169.  
  170.  
  171. # define the actions for each choice
  172.  
  173. case $character in
  174.     0 ) Exit=0
  175.     ;;
  176.     1 ) defaults write com.apple.finder AppleShowAllFiles True; killall Finder
  177.     ;;
  178.     2 ) defaults write com.apple.finder AppleShowAllFiles False; killall Finder
  179.     ;;
  180.     3 ) cd ~/Library; open .
  181.     ;;
  182.     4 ) cd ~/Library/Preferences; open .
  183.     ;;
  184.     5 ) killall Finder
  185.     ;;
  186.     6 ) killall Dock
  187.     ;;
  188.     7 ) sysprefs_to_default
  189.     ;;
  190.     8 ) sudo killall -HUP mDNSResponder && echo "DNS Cache flushed!"
  191.     ;;
  192.     9 ) purge && echo "Memory purged!"
  193.     ;;
  194.     10 ) rename_files
  195.     ;;
  196.     * ) clear; echo "Sorry that's not a valid choice. Please try again or press 0 to exit."
  197. esac
  198. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement