Advertisements

Category Archives: Mac OS X Tips & Tricks

#MacOsX : Terminal Cheat Sheet

If you are a *nix geek like me you can’t but love the command prompt.
One of the best tool to improve the plain old terminal is an utility called tmux. You can install through Homebrew.
Now, there are many commands to remember to play nicely with the terminal, and sometimes a little remind might be useful, that’s why cheat sheets exist.
Here is mine, enjoy.

Advertisements

#MacOsX : SSH SOCKS Proxy (SSH Tunnel Web Traffic)

After PRISM scandal you may feel the need to secure your connection and protect your privacy. Then it is a good idea to tunnel web traffic through a secure encrypted connection. This allows your traffic to traverse a local network without being visible to snoopers, even when visiting unencrypted web sites.

What you need:

  • a modern browser like Firefox, Chrome or Safari (they support SOCKS4 protocol)
  • ssh client (already installed in Mac Os X)
  • a shell account (with ssh access)

If you don’t have a shell account, you can find a free one HERE, or HERE, or HERE, or HERE.

To start the local proxy type:

ssh -D PORT user@host

where PORT is a local port between 1024 and 65535 (they do not require super user privileges), user is the username at the remote machine, and host is the identifier of the remote host.

That’s not enough, you need to configure the system to use the proxy. Go to System Preferences > Network > [select active interface] > Advanced... > Proxies and check SOCKS Proxy.
Then modify SOCKS Proxy Server info to use the PORT you chose before.

That’s it! From now on all connections on the active network interface will be tunneled through the proxy. 😎

NOTE1: you may want use proxy browser settings instead of system wide proxy settings, so you can tunnel only part of the traffic (e.g. the most sensitive one). This is easy, but the procedure slightly change between different browsers.

NOTE2: you may need to add the option -p HOST_PORT if the remote host doesn’t use the standard ssh port 22, e.g.:

ssh -D PORT user@host -p 666

#MacOsX : Show Hidden Files and Folders

In *NIX systems file and folders beginning with a dot (e.g., .name) are not visible in the Finder (also known as file browser). Since Mac Os X it’s a certified UNIX that’s also the case. If you use the terminal you can use the command:

ls -a

However, most people will use regular Finder. To enable view of hidden files in the Finder use this command:

defaults write com.apple.finder AppleShowAllFiles -bool TRUE

and then restart the finder with the following command:

killall Finder

To revert the changes use the same command, but replace TRUE with FALSE.

#MacOsX : vimrc

If you are looking to configure Vim you find the default configuration file in:

/usr/share/vim/vimrc

Copy and rename it in your home directory:

cp /usr/share/vim/vimrc ~/.vimrc

However it is bare minimal so it is better if you personalize it a bit. One very simple example is the following:

" Configuration file for vim
set modelines=0 " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
" Use Vim defaults instead of 100% vi compatibility
set nocompatible

" more powerful backspacing
set backspace=2

" Display line numbers on the left
set number

" Allow intelligent auto-indenting for each filetype
" and for "plugins that are filetype specific.
filetype indent plugin on

" Fallback when no filetype-specific indenting is enabled
set autoindent

" Enable syntax highlighting
syntax on

" Display the cursor position
set ruler

" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup

#MacOsX : Fix Mountain Lion Slow Shutdown

Ok, actually there are many good reasons to wait a bit of time before send a SIGKILL to processes (like giving them time to write things on disk or finish an upload on the iCloud), however the “slow” shutdown could be annoying, so try this:

sudo launchctl unload /System/Library/LaunchDaemons/com.apple.coreservices.appleevents.plist

sudo defaults write /System/Library/LaunchDaemons/com.apple.coreservices.appleevents ExitTimeOut -int 2

sudo launchctl load /System/Library/LaunchDaemons/com.apple.coreservices.appleevents.plist

This set the shutdown timeout to 2 sec instead of the default value (20).

#MacOsX : Enable Quicklook Text Selection

Quicklook is a beautiful and powerful feature of Mac Os X (take a look here to know what is capable of) but it is somewhat weird that it doesn’t allow text selection.

To enable text selection in Quicklook:

defaults write com.apple.finder QLEnableTextSelection -boolean YES

killall Finder

 

#MacOsX : Show Remote Disks

There are Macs without disk drives. You can access CD/DVDs from another Mac over the network allowing remote disk.

This option allows you to always see remote drives within Finder:

defaults write com.apple.finder EnableODiskBrowsing -boolean YES

killall Finder

#MacOsX : How Cut & Paste Works in Mac OS X

Yep, Mac world is only about Drag & Drop but if you feel nostalgic of PC’s world you can move files the old way, just do this:

  • selct file/files and hit

    Command + C

  • move to another location an hit

    Command + Option + V

#MacOsX : Reset NVRAM, PRAM and SMC

Sometimes after a software (system) or hardware upgrade even Macs can have some problems; if you have tried every solution without success you could try this.

Every Mac stores certain settings in a special memory area even if it is turned off. On Intel-based Macs, this is stored in memory known as NVRAM; on PowerPC-based Macs, this is stored in memory known as PRAM.

Resetting NVRAM and PRAM may solve lot of problems and could be required if you upgrade SSD or Mac firmware (more tips on SSDs here).

Another step to try is Resetting the System Management Controller (SMC). An SMC reset should only be attempted after all other standard troubleshooting has been performed.

 

 

#MacOsX : Disable Auto-Save and Versions in Mac OS X

Auto-Save and Versions are excellent features in Mac OS X, but some advanced users are annoyed by  them as they often don’t want to save intermediate versions of their work.
Moreover some apps write lots of data on disk (e.g. iMovie and iBooks Author) and this can shorten the life of SSD (look here for more tuning for SSDs).
If you know the name of the app plist you want to disable auto-save and Versions for, you can just plug the name into the defaults write command:

defaults write app-plist ApplePersistence -bool no

If you don’t know it then you can find it with the following command:

osascript -e 'id of application "NAME OF APP"'

Now if you enter the Versions window, auto-save list will be empty and there are no versions to restore to. You’ll probably want turn off File Locking too.

NOTE: some sandboxed apps require another command in addition:

defaults write app-plist AutosavingDelay -int 0

This is expecially true for TextEdit as it is the only Apple app that uses “old-style” autosaving and this causes issues with the sandbox in Lion/Mountain Lion.

NOTE2: It seems that the preference can be set globally but it may cause the login process to become very slow and possibly cause other unexpected behaviour:

defaults write -g ApplePersistence -bool no

#MacOsX : Turn Off File Locking

Mac OS X Lion has introduced automatic file locking for files that hasn’t been edited recently.

To Disable File Locking:

  • open System Preferences > Time Machine
  • click on Options
  • uncheck the box next to “Lock documents [2 weeks] after last edit” or modify the value as preferred
  • done 🙂

#VMware Fusion : Fix Ubuntu Linux “Host SMBus controller not enabled!” [UPDATED]

Ubuntu guest instances in VMware sometimes come up with the boot error message:

piix4_smbus 0000:00:007.3: Host SMBus controller not enabled!

This error is being caused because VMware doesn’t actually provide that level interface for CPU access, but Ubuntu try to load the kernel module anyway.

How to fix it:

  • sudo nano /etc/modprobe.d/blacklist.conf
  • add the line:
    blacklist i2c-piix4
  • reboot

NOTE: for older versions use blacklist i2c_piix4 instead.
NOTE: it works both in VMWare Fusion 5 and 6, and Ubuntu LTS 12.04 and 14.04

#MacOSX : Make your Mac a Wireless Network Bridge

Sometimes you need to extend wireless field; you can do it transforming your Mac as a Wireless Network Bridge.

Why  your Mac? Maybe a new shining Mac Book Pro? Well, let’s say your city has been hit by a big earthquake, so you had to leave your house, but your wireless network still works. Mobile Network won’t  work due to excessive overhead but you can still access internet to contact your friends and family. Sharing your internet connection give this chance also to many other people (this has been happened to me recently).

First you need a Switch or a Router or a Wireless Access Point and Ethernet cables.

Then:

  • Connect your mac to your wireless network
  • Connect Switch / Router / Wireless Access Point to Mac Ethernet port
  • Go to System Preferences -> Sharing
  • Check Internet Sharing
    • Share your connection from: Wi-Fi
    • To computers using: Ethernet and Bluetooth PAN
  • Let DHCP enabled

NOTE: this way you can connect to internet while you can maintain a secure distance from damaged buildings.

#MacOSX : Subversion Server

You know, Mac OS X is a UNIX system based on FreeBSD, so you can do a lot of NERD things out of the box.

This time you will learn how to setup a Subversion Server:

  1. Open Terminal app
  2. Type:
    mkdir -p /Library/Subversion/Repository
    cd /Library/Subversion/Repository
    svnadmin create myproject
  3. Great! Now that you have created the first repository, you need to configure it; type:
    vim /Library/Subversion/Repository/myproject/conf/svnserve.conf

    You’ll see ### commented lines. The lines with the single “#” comment marks are the ones we need to edit. You’ll want to remove the comments (#) and customize these settings to suit your project’s needs:

    • password-db : this specify text file that stores the usernames and passwords of authorized users for your repository. Unless otherwise specified, it will be assumed that this file is stored in your projects “conf” directory. When you create your repository a “passwd” file is created by default.
    • realm : realm tells clients what they are connecting to. It’s recommended you customize this to something like <Project Name> Subversion Repository.
    • anon-access : this directive indicates what anonymous users are allowed to do with your repository. You should set it to none.
    • auth-access : determines what permission level authorized users will have. In almost every case this will be set to write.
  4. Now you must edit password-db file; you can add as many users to your repository(s) as you want. Add at least one user for yourself so that you can begin committing to your repository:
    vim /Library/Subversion/Repository/myproject/conf/passwd
  5. Next you need to change permissions on the Repository directory so that svnserveis permitted to make changes to the files stored there:
    sudo chown -R root:admin /Library/Subversion/Repository
    sudo chmod -R ug+rwX,o= /Library/Subversion/Repository
  6. Start Subversion Server:
    svnserve -d -r /Library/Subversion/Repository
  7. Check if it works:
    cd
    mkdir project
    cd project
    svn checkout --username <user> --password <user_password> svn://localhost/myproject
  8. If it works you should have myproject directory in Repository. Well Done.

NOTE1: /Library/Subversion/Repository is just an appropriate example for Repository, but you can choose every other location.

NOTE2: in svnserve.conf and passwd files remove every white spaces at the beginning of non empty lines or it will not work.

NOTE3: if you want allow users to connect from internet you should set port forwarding on TCP port 3690 (svn default).

NOTE4: check Subversion Complete Reference for more info.

#MacOSX : Enable Half-Star Ratings in iTunes

iTunes allows users to rate songs on a 1 star to 5 star basis, but what if a song is somewhere in the middle of the rating scale, not quite worthy of 4 stars but not a 3 star song either?

For more precise personal ratings, enable the half-star rating option in iTunes:

  1. Open Terminal app
  2. type:
    defaults write com.apple.iTunes allow-half-stars -bool TRUE
  3. Quit and relaunch iTunes for changes to take effect. To give something a half star, click and slide the star rating scale until the 1/2 value shows.

NOTE: removing the half stars moves the song rating to the star below it, so a 3 1/2 star song would turn into a 3 star song, and so on, but the metadata of the songs are still in half-star increments.
So, if you turn the option back on again, the ‘correct’ half-star ratings would show and be intact.

#MacOSX : Change Launchpad Background

If you do not like default background of Launchpad you can easily change it:

  1. Go to Launchpad
  2. Hit Ctrl + Alt + Cmd + B
  3. Hit more if you want

That’s All. 🙂

 

#MacOSX : Add Dock Spacing using OnyX

Onyx is a powerfull App which does a lot of things. You can tweak user interface too; what we want to do is adding invisible spaces in the dock.

  1. Start Onyx and enter your administrator password
  2. Go to Parameters tab
  3. Choose Dock tab
  4. Click on the buttons at the bottom: Applications or Others
  5. OnyX will now reboot the Dock

This is how it look like:

#MacOSX [*NIX]: MAC Address Spoofing

MAC Address is a unique identifier of 48 bits assigned to network interfaces.

This Address is unique in the world, so it does identify you, everywhere.

From a Security & Privacy perspective this is not good at all!!!

How to modify it:

  1. Open Terminal app.
  2. Type:
    sudo ifconfig [en0-en1] ether [MAC Address]

    • where you can choose en0 for wired ethernet interface or en1 for airport interface
    • MAC Address is something like FF:FF:FF:FF:FF:FF
      where there are 6 groups of 2 exadecimal symbols separated by colons (:)
  3. Insert your Administrator password.
  4. Go to Network System Preferences, select active interface and push Advanced… button.
  5. In TCP/IP tab click on Renew DHCP Lease button.
  6. You should now see your new MAC Address in Hardware tab.

NOTE: you can set Configure: Manually in Hardware tab to manually set MAC Address and avoid using Terminal.

NOTE2: if you do not renew DHCP Lease you may loose network connectivity.

NOTE3: if you have set MAC Address through Terminal it will be restored to it own default after reboot or shutdown.

NOTE4: some Hotels or private Acces Point use MAC Filtering to prevent abuse of their network. The changing of MAC Address allow you circumviate this kind of restrictions (see MAC Spoofing). This is NOT legitimate, so if you are not an evil user and you need emergency network access, try to set your MAC Address to FF:FF:FF:FF:FF:FF (could not work of course). This way System Administrator will readily understand what is going on. 😉

#MacOSX : Display EDID [UPDATED]

EDID (Extended Display Identification Data) enables Mac OS X to know what kind of monitor is connected to it.
Why are we interested in it? If we know the exact model of LCD connected to our mac we can retrieve who is the manufacter of the panel (which often it is not the brand under the monitor is sold) and its properties (like response time, contrast and brightness) as Apple doesn’t specify they in its own products.

So here we go:

  1. Open Terminal app.
  2. Type (see this comment):
    ioreg -lw0 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6
    ioreg -lw0 -r -c "IODisplayConnect" -n "display0" -d 2 | grep IODisplayEDID | sed "/[^<]*</s///" | xxd -p -r | strings -6
  3. Second line is what we are looking for.

NOTE: if you are interested in how this work, you can type in Terminal (but be ready for a full NERD immersion):

  • man bash
  • man ioreg
  • man grep
  • man sed
  • man xxd
  • man strings

Don’t say i haven’t Warned you! 😀

#MacOSX : System Preferences Archives Pane

Mac OS X support zip & unzip files natively, but you can’t find how to configure it in System Preferences.

Archives Pane exists but it is not installed by default, so you must install it first:

  1. Go to (Shift-Command-G):
    /System/Library/CoreServices/Archive Utility.app/Contents/Resources/
  2. Double-click on Archives.prefPane
  3. Insert your admin password
  4. From now on you have Archives pane in System Preferences

NOTE: it works on Mac OS X Lion, Snow Leopard and Leopard.

%d bloggers like this: