amazon

February 9, 2014

Top 25 OS X Terminal commands - HACKS

Top 25 OS X Terminal commands - HACKS

Change settings and access hidden features on your Mac 

Top 25 OS X Terminal commands 

Terminal (in Applications/ Utilities) gives you direct access to the UNIX system that underpins OS X. By typing specific commands into your Terminal window, you can make changes, open settings or access features that aren't available by any other means.
After typing one of the commands offered in this tutorial, press Return to activate it, and anything offered in quotes is typed without the quote marks themselves.
Commands split over two or more lines here should be typed in their entirety – you don't press Return halfway through. And bear in mind that some commands are case-sensitive, so be true to what's here.
One final word of warning: all the tips in this article have been thoroughly tested, but experimenting with the Terminal is not a task to be undertaken lightly. Do not try to modify or adapt these hacks unless you really know what you're doing.
01. i… Robot
Your Mac can talk to you. Using a robotic voice reminiscent of a 50s sci-fi flick, it can ask after your health, tell you a joke or say anything else you care to type. It's a simple trick.
Just open the Terminal application (found in Applications > Utilities), enter: 

say MacFormat
…And the Terminal robot utters the name of MacFormat magazine. Obviously it doesn't have to be MacFormat – type anything you like. Give it a go, it's fun.
02. Back up at will
By default, Time Machine backups take place every hour, but you can change this through Terminal. To make it back up every half an hour instead, simply type:
sudo defaults write /System/Library/Launch Daemons/com.apple.backupd-auto StartInterval -int 1800
The '1800' at the end of this command is half an hour, expressed in seconds. You can change this figure to suit: for example, to back up once an hour again, replace it with '3600', for two-hour backups, '7200'.
Always remember to be especially careful with commands that begin 'sudo'. These are system-level commands that can cause huge problems if misused, which is why you're asked for your administrator's password the first time you try one.
03. Logon greetings
Another sudo – and therefore dangerous – command that enables you to add a message to the login screen. In Terminal, type:
sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Your Message"

Top 25 terminal tips: logon message
Replace 'Your Message' with whatever it is you want to display, of course, but be careful with your punctuation. Some characters (exclamation marks, for instance) stop the command from working.
To remove the message, type:
sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText ""
04. Play games in the Terminal
As you may know, OS X is UNIX based. Emacs, a text editor, forms part of the UNIX system, and it contains some Easter egg games, including the ever-popular Tetris, Pong and Snake.
First you must find your Emacs version number. In the Terminal, type cd /usr/share/emacs/ And press Return. Now type 'ls' and press Return again. You're given your Emacs version number (1.21, for instance). Now, write it down.
Then enter the following:
ls /usr/share/emacs/[VERSION]/lisp/ play
Replace [VERSION] with the number obtained earlier. You get a directory of all the available games. Make a note, or take a screenshot.

Top 25 terminal tips: pong
Now switch to Emacs through Terminal by simply typing 'emacs'. To access the games, press Esc then x and type the name of the game you wish to play, before pressing Return.
You can switch to the next game by pressing Esc then x and the name of the next game you wish to try. Have fun!
05. Fix window sizes in FFView
01. Resize problem


Top 25 terminal tips: ffview 1

FFView is a great sequential image viewer, but its Page width Mode resizes its window every time you turn to the next image. This is very annoying if you want to set – and stick to – your own window size. What to do?
02. Resize resolution

Top 25 terminal tips: ffview 2
Terminal solves the problem. Type:
defaults write com.feedface.ffview udn_dont_resize_img_ win 1
The window now remains a constant size. To reverse this, enter the code again, replacing the '1' at the end with '0'. Now restart the app.
03. Want comics?

Top 25 terminal tips: ffview 3
There's a wealth of downloadable free comics available on the web. For example, mobile comic publisher Robot Comics offers a list of high-quality, free-to-download material suitable for reading on your Mac with FFView. Check it out here.
06. Get a massive Dock
If you want giant-sized magnified Dock icons, enable Magnification in System Preferences > Dock, and in Terminal type:
defaults write com.apple.dock largesize -int 512; killall Dock

Top 25 terminal tips: mssive dock
This increases their maximum size to 512x512 pixels. You can substitute another figure if you wish, but don't go any higher than 512. To switch this effect off, just return to the Dock's preferences and move the Magnification slider back.
07. Hybrid Dock folders
For a different version of a Dock folder or Stack's List option, type:
defaults write com.apple.dock use-new-liststack -boolean YES; killall Dock
This gives you an interesting hybrid of the List and Grid viewing options. Your List view icons are bigger, and if there are more items than fits the window, you can scroll through them in the same way as you would in Grid view.
Also like Grid view, clicking on a folder now opens it within the Stack. If you find you don't like these changes, type the command again, replacing 'YES' with 'NO'.
08. Inspect the web
Safari's Web Inspector offers a great deal of detail about web pages, and it's invaluable for serious web developers. You can activate it using Safari's Debug Menu outlined elsewhere in this tutorial, but if you only want the Web Inspector, type:
defaults write com.apple.Safari WebKit DeveloperExtras -bool true
After restarting Safari, you can now access the Web Inspector by right-clicking on a web page and selecting it from the contextual menu.
As you might guess, you can deactivate this feature by repeating the command, but replacing 'true' with 'false' at the end and restarting Safari once more.
09. Debug iCal
Like many OS X applications, iCal has a Debug Mode that can be activated through Terminal. Type:
defaults write com.apple.iCal IncludeDebugMenu YES
A new menu bar pull-down titled Debug appears. You can hide it again by repeating the code but replacing 'YES' with 'NO'; note that iCal must be restarted for changes to take effect.
10. Debug Address Book
Address Book also has a hidden debug menu. To enable it, type:
defaults write com.apple.addressbook ABShow DebugMenu -bool YES
The Debug pull-down appears in the menu bar. To disable it again, repeat the command and replace 'YES' with 'NO' at the end. The application must be closed and restarted for these commands to take effect.
11. Enable Safari debug menu
To enable a debug menu in Safari 4, type; defaults write com.apple. safari IncludeInternalDebug Menu 1 Quit Safari and restart it for the hack to take effect, giving you an extra menu bar pulldown labelled Debug.

Top 25 terminal tips: safari debug menu
To get rid of it again, repeat the command, replacing the '1' at the end with '0'. A restart is again required.
12. Enable x-ray folders in Quick Look
01. Folders can look dreary
If you highlight a file in Finder and press [Space] or click on the eye-like icon in the toolbar, you activate Quick Look, giving you information about the item in question and possibly a preview of the file. Folders look pretty dull in Quick Look, as you can see here.
02. See through the veil
Fortunately, there is a way to spice up your folder viewing experience, and Terminal is the source: to make Quick Look give you an x-ray image of a folder, simply type:
defaults write com.apple.finder QLEnableXRayFolders -boolean YES
03. X-ray vision is yours
Quick Look now offers an x-ray view of a folder, with an icon that shows you what's inside it. To disable this feature once more, type the code offered in step two again, replacing 'YES' with 'NO'. Quick Look folders are returned to their former state, with no x-ray view.
13. Translucent icons
To turn the Dock icons translucent for applications that are open but hidden, type;
defaults write com.apple. Dock showhidden -bool YES; killall Dock

Translucent icons
Repeat the command, replacing 'YES' with 'NO' to disable this feature once more. Icons for applications that are already hidden when you activate this feature will not appear translucent unless you Show and then Hide them again.
14. Recently used
This somewhat intimidating code introduces a new Stack into your Dock, showing a list of your recently used applications:
defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }'; killall Dock

Top 25 terminal tips: recently used
Type it carefully. It's a really useful feature. When the new Stack is in your Dock, you can right-click on it and change it from showing Recent Applications to Recent Documents, Recent Servers, Favourite Volumes or Favourite Items.
It can be displayed in Fan, Grid or List View, just like a regular stack. If you want to get rid of it again, just drag it out of the Dock.
15. Expose your Dock
By default, clicking and holding on the Dock icon for an active application in Snow Leopard activates Dashboard Exposé, showing all of that application's currently-open windows. In Leopard, of course, this gave you a contextual menu; that's something you can access in both operating systems by right-clicking on the icon in question.
If you're running Snow Leopard but prefer Leopard's way of doing things, type the following Terminal command:
defaults write com.apple.dock show-exposemenus -boolean no; killall Dock
Repeating the command with 'YES' instead of 'NO' returns your Dock's Exposé functions to normal.
16. Grid view highlights
If you open a Stack in Grid view, you can navigate through its enclosures using your keyboard's arrow keys, with the currently selected icon highlighted by a grey gradient box. However, if you drag your mouse pointer over the Grid, no such highlighting appears – unless you use this Terminal command:
defaults write com.apple.dock mouse-over-hilitestack -boolean YES; killall Dock
You now get the same grey background box during mouse-overs as you do when navigating through the Grid using the keyboard. Replace 'YES' with 'NO' to switch this off again, though we doubt you'll want to.
17. Dock the gloss
If you're not too keen on the 3D Dock, with its shiny glass finish showing reflections of the application icons, use this tip to switch to something a little simpler:
defaults write com.apple.dock no-glass -boolean YES; killall Dock
Your Dock background is now a much plainer translucent black design with a thin white outline. Icons are no longer reflected in the Dock, and open applications are indicated by a white dot instead of a blue floodlight.
If you decide you prefer the 3D look after all you can repeat the command substituting 'NO' for 'YES', so you've nothing to lose by giving it a go.
18. Search your music
When you highlight a track in your iTunes library, you get a right-facing arrow in a circle. Clicking on this searches the iTunes Store for similar material. However, using this Terminal input, you can get it to search your library instead:
defaults write com.apple.iTunes invertStore Links -bool YES
Restart iTunes to activate it, and repeat the command with 'NO' replacing 'YES' to switch things back to their default behaviour.
19. Drag Dashboard widgets onto your Desktop
One of the most interesting Terminal tips enables you to drag your widgets out of the Dashboard and onto the Desktop, where they float above open applications and Finder windows akin to the 'Gadgets' in Windows Vista's Sidebar. To activate it, type:
defaults write com.apple.dashboard devmode YES

Top 25 terminal tips: dashboard widgets
You must then log out and back in again, or restart your machine. You can now capture a widget by clicking and holding it, and pressing F12 to dismiss the Dashboard and drop it on your desktop.
By capturing a widget that's on your desktop and pressing F12, you can return it to your Dashboard too. Widgets placed on the Desktop function just like they do on the Dashboard.
To disable this feature, repeat the code simply replacing 'YES' with 'NO'. Again, you must log out and in again or restart your machine for the change to take effect, after which widgets that are already on the desktop can be returned to the Dashboard, but there they must remain.
20. Expanded Save view
The Save command brings up a dialog window, enabling you to choose a title, where your document will save to and possibly the format in which it will be saved, depending on the application in question.
Next to the title, there's a blue button with a triangle pointing down. Pressing this expands the dialog window, giving it a similar format to a Finder window. If you want this window to appear in its expanded form by default, type:
defaults write -g NSNavPanelExpandedState ForSaveMode -bool TRUE
If needed, just replace 'TRUE' with 'FALSE' to revert to how things were.
21. Faster Screen Sharing
MobileMe's Screen Sharing facility is an excellent feature, but depending on your internet connection, it can be very sluggish. Thankfully, there's an easy way of speeding it up by using a Terminal command to reduce the image quality of the shared screen:
defaults write com.apple.ScreenSharing controlObserveQuality 1
This reduces the screen to its lowest possible quality setting, giving you a black and white image. You can replace the '1' at the end of the command with the numbers '2' to '5', offering progressively higher quality screens. '2' gives a greyscale image, '3' offers eight-bit colour, '4' is 16-bit colour and '5' takes you back to full colour, the default setting.
22. Screenshot names
If you capture a screenshot in Snow Leopard, it's automatically titled 'Screen shot', followed by a date and time. You can change this using a Terminal command:
defaults write com.apple.screencapture name "Anything you like"; killall SystemUIServer
Simply change 'Anything you like' to whatever it is you wish to call the screens you capture – the date and time remain unchanged. To go back to the default, simply use this command with 'Anything you like' replaced by 'Screen shot'.
23. Reveal hidden files
There are several applications that let you look at OS X's hidden files, such as resource forks, but there's also a very simple command you can employ from the Terminal:
defaults write com.apple.finder AppleShowAll Files TRUE; killall Finder
Be careful with this one. Those files are hidden for a reason, and while it's interesting to see what's there, don't fiddle with them unless you know what you're doing. To turn off this feature, repeat the command replacing 'TRUE' with 'FALSE'.
24. Copy, Gold Leader!
This must be the strangest Terminal command ever. Go on, type:
telnet towel.blinkenlights.nl

Top 25 terminal tips: star wars
You're treated to the Star Wars movie, retold in ASCII art. Wait for the prefilm credits to end, and make sure you don't resize the Terminal window, or the graphics won't format properly.
25. Quit Finder like any other app
With this handy command, you can quit out of Finder in the same way you would any other app:
defaults write com.apple.finder QuitMenuItem -bool YES; killall Finder

Top 25 terminal tips: quit finder
A Quit option now appears at the foot of the Finder menu. To remove it, enter the code again, replacing 'YES' with 'NO'.

 

No comments: