Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/bash
- #FastTasks by Applehelpwriter.com, 2012.
- #Version 1.2
- #changelog
- #version 1.2: added confirmation msg upon success for options 8 & 9
- # Requirements:
- # Needs OS X 10.8, Mountain Lion, but should work on 10.7
- # Menu option 8 won't work on 10.6 or earlier
- # This script lets you perform 10 common tasks from one menu
- # 1. Reveal hidden files in Finder
- # 2. Hide hidden files in Finder
- # 3. Open the User Library in Finder
- # 4. Open the User Library Preferences folder in Finder
- # 5. Kill and Relaunch the Finder
- # 6. Kill and Relaunch the Dock
- # 7. Reset System Preferences to Default (requires restart)...
- # 8. Flush DNS Cache (requires Admin password)
- # 9. Free system memory (purge)"
- # 10. Batch change file extension
- #HOW TO USE
- # Step 1
- # Create a plain text file in text edit and copy the
- # entire contents of this file, including these comments, into it.
- # Save the script to your desktop as 'FastTasks' without the quote marks
- # make sure that it's saved as plain text, not RTF.
- # Step 2
- # Open Terminal.app and paste the following line without the '#'
- # sudo chmod 755 ~/Desktop/FastTasks
- # press 'return' on your keyboard
- # enter your Admin user password to authorise the change
- # - what you just did is turn the plain text script into an
- # executable program file.
- # Step 3
- # Now let's copy the script to somewhere where Bash looks for programs.
- # Paste the next line without the # into Terminal.app
- # cp ~/Desktop/FastTasks /etc/bin/FastTasks
- # then press 'return' on your keyboard.
- # Step 4
- # Now you can use the script by typing 'FastTasks' in a
- # Terminal window or you can run FastTasks by double-clicking
- # it in Finder or on the Desktop.
- # If the Terminal window remains open after FastTasks has
- # completed, change the following settings
- # in Terminal's Preferences:
- # Preferences > Settings > Shell > When the shell exits...
- # Change the drop down menu from 'Don't close the window' to
- # 'Close if the shell exited cleanly'.
- # END OF NOTES
- # START OF SCRIPT
- # Define the function for batch file extension changes
- function rename_files
- {
- clear; echo ""
- echo "**** Change file extension ****"
- echo "This utility allows you to change multiple files with one extension"
- echo "to another extension"
- echo "(e.g., change a list of jpg files to tiffs)"
- echo ""
- echo "PREPARATION:"
- echo "Before proceeding, place the files you want to change on the Desktop."
- echo "Ensure there are no other files with the same extension on the Desktop."
- echo ""
- echo "Are the files you want to change on the Desktop?"
- echo -n "Press 1 for 'yes' or Press 2 for 'no' "
- read text
- if [ "$text" = "1" ]; then
- clear;
- echo "Enter the old file extension or press Ctrl-C to cancel"
- echo -n "(do not include the dot before the extension)... "
- read oldex
- echo "Enter the new file extension or press Ctrl-C to cancel"
- echo -n "(do not include the dot before the extension)... "
- read newex
- echo "Confirm Change $oldex to $newex?"
- echo -n "(press 'enter' to confirm, Ctl-C to escape)"
- read
- # command to perform the batch change
- cd ~/desktop; for i in *.$oldex; do mv "$i" "${i/.$oldex}".$newex; done
- #echo "Your files have been successfully changed."
- #else echo "Sorry no files were changed."
- #fi
- else echo "Please move the files to the Desktop before trying again. Thank you."
- fi
- }
- # define function for changing sys prefs to default
- # useful if you have problems with system preferences
- function sysprefs_to_default
- {
- clear;
- echo "**** Return System Preferences to default values ****"
- echo ""
- echo "This utility can help solve problems such as System Preference panes not opening"
- echo "or only opening after a lengthy spin of the pinwheel..."
- echo ""
- echo "This utility is harmless, but it will return all your system preferences back"
- echo "to default, so you may have to set some system pref choices up again."
- echo ""
- echo "WARNING - save any unsaved work in open apps before proceeding."
- echo ""
- echo -n "Press enter to reset System Prefs or Ctl-C to cancel..."
- read
- rm ~/Library/Preferences/com.apple.systempreferences.plist; clear;
- echo "You must restart your mac to complete the change to default preferences."
- echo ""
- echo "1 = quit FastTasks and shutdown manually"
- echo "(choose this if you have unsaved work in open Apps)"
- echo ""
- echo "2 = quit FastTasks and restart IMMEDIATELY"
- echo "(requires Admin password - you could lose any unsaved work)"
- echo -n "Enter 1 or 2..."
- read answer
- case $answer in
- 1 ) exit=0
- ;;
- 2 ) sudo shutdown -r now
- ;;
- * ) exit =0
- esac
- }
- # Text for the user menu options:
- clear;
- echo "MENU:"
- echo "1 = Reveal hidden files in Finder"
- echo "2 = Hide hidden files in Finder"
- echo ""
- echo "3 = Open the User Library in Finder"
- echo "4 = Open the User Library Preferences folder in Finder"
- echo ""
- echo "5 = Kill and Relaunch the Finder"
- echo "6 = Kill and Relaunch the Dock"
- echo ""
- echo "7 = Reset System Preferences to Default (requires restart)..."
- echo ""
- echo "8 = Flush DNS Cache (requires Admin password)"
- echo "9 = Free system memory (purge)"
- echo ""
- echo "10 = Batch change file extension..."
- echo ""
- echo "or press 0 = Exit FastTasks"
- echo ""
- # Get the user's choice
- echo -n "Enter a number between 0 and 10: "
- read character
- # define the actions for each choice
- case $character in
- 0 ) Exit=0
- ;;
- 1 ) defaults write com.apple.finder AppleShowAllFiles True; killall Finder
- ;;
- 2 ) defaults write com.apple.finder AppleShowAllFiles False; killall Finder
- ;;
- 3 ) cd ~/Library; open .
- ;;
- 4 ) cd ~/Library/Preferences; open .
- ;;
- 5 ) killall Finder
- ;;
- 6 ) killall Dock
- ;;
- 7 ) sysprefs_to_default
- ;;
- 8 ) sudo killall -HUP mDNSResponder && echo "DNS Cache flushed!"
- ;;
- 9 ) purge && echo "Memory purged!"
- ;;
- 10 ) rename_files
- ;;
- * ) clear; echo "Sorry that's not a valid choice. Please try again or press 0 to exit."
- esac
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement