Control the volume of your Mac from the Terminal

Recently when I was sitting on my couch in the living room, I have realised that the iTumes running on my iMac (which is in a different room) is playing bit too loud. As it was too comfortable to get up and go to the machine to reduce the volume I found an easy method using the OS X terminal. Here is how I did it.

Connected to the iMac using ssh from my laptop.

Entered the following code

osascript -e 'set volume output volume 10'

Here the volume scale is from 0 to 100.

That’s all.

Share and Enjoy:
  • Digg
  • del.icio.us
  • MisterWong
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati

Quickly switch between users in OS X

In OS X (Tiger, Leopard or Snow Leopard) it is really easy to switch between users without logging out of the system. However, you need to activate a system preference setting in order to activate the switch mode.

  1. Go to System Preferences and select “Accounts”. If you are not an admin user click on the small padlock symbol(padlock) and login as an admin. user.
  2. Click on “Login Options” and check the “Enable fast user switching.

user_switch

That’s all. Now if you want to switch as a different user, you can select the appropriate user from the top right corner of the main menu. Switching users does not pause activities of the current user except iTunes or video playback.

Share and Enjoy:
  • Digg
  • del.icio.us
  • MisterWong
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati

Snow Leopard is out

After all most two years of development and testing Apple has released it’s new operating system on the 28th August 2009. It is two months earlier than previously planned but many blog sites have correctly predicted the early arrival. According to Apple, this release is all about refinement not reinvention. They have done lot work cleaning up the code and refining the existing features of Leopard to make it faster and even more user friendly. It also includes couple of important new features as well.

Snow Leopard

Snow Leopard

The Snow Leopard is taking the advantage of 64-bit processor power. Nearly all system applications — including the Finder, Mail, Safari, iCal, and iChat — are now built with 64-bit code. This enables the Macs to address up to 16 terabytes of memory.

What are the major new features of Snow Leopard?
New look and new features in Exposé and Stacks
sls_tacks
Exposé is now integrated in the Dock, so when you click and hold an application icon in the Dock and all the windows for that application will unshuffle so you can quickly switch to another one. Exposé windows are now displayed in an organized grid, making it even easier for quick search. The stacks are now scrollable, so you can easily view all items. You can also navigate back and forth through folders in a stack to see all the files inside it.

QuickTime X
Snow Leopard comes with an optional new version of Quick Time known as QuickTime X. It has got rid of window frames and menu functions made available only when required. At other times they are not visible.
qtx
OpenCL
The new OpenCL technology takes the power of graphics processors and makes it available for general-purpose computing. No longer will graphics processors be limited to graphics-intensive applications such as games and 3D modeling. Now the developers can use OpenCL in their applications to greatly improved speed.

Grand Central Dispatch
Grand Central Dispatch (GCD) in Mac OS X Snow Leopard makes it much easier for developers to squeeze every last drop of power from multicore systems. With GCD, threads are handled by the operating system, not by individual applications. GCD-enabled programs can automatically distribute their work across all available cores, resulting in the best possible performance whether they’re running on a dual-core Mac mini, an 8-core Mac Pro, or anything in between.

Installation requires less space
Due to refinements done in the core system Snow Leopards saves up to 7GB of free space. As I was checking the capacity of the HDD, I also noticed that the size it displayed on Snow Leopard was different to Leopard. As it turns out Snow Leopard is calculating capacity in base 10 rather than base 2 which is used by Leopard. More information can be found here.

Installation
The installation went quit smooth. It took me around 40 min. for upgrading from Leopard. Although it is not official you may be able to upgrade to SL from Tiger. You should also aware that the Snow Leopard will not run on PPC based Macs.

Exchange Server support
exchange_support
Snow Leopard includes built-in support for the latest version of Microsoft Exchange Server. So you can use all the features and applications without having to install Microsoft products.

Read Mac volumes on Windows
Using Boot Camp 3.0, you can open and read files on Mac OS X volumes when booted into Windows. You can also copy photos, documents and other files from a Mac OS X volume into the Windows partition.

My verdict
I have seen a significant performance boost on my Core Duo Mac Mini with 1.5GB of RAM. Especially, Safari, Mail and other core applications run way faster than with Leopard. Viewing PDF documents on Preview is also much smoother than before. Now it is possible to restore any item accidently sent to Trash using “Take Back” option.

It should be noted that there are couple of applications still not running properly on Snow Leopard. Check out this link for compatibility issues.

I would strongly recommend any one running Leopard on an Intel Mac to upgrade to Snow Leopard. It is worth every penny!

Share and Enjoy:
  • Digg
  • del.icio.us
  • MisterWong
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati

Create your own commands using alias

In Unix based operating systems it is quit easily create your own convenient commands using alias. This is particularly helpful when you use certain shell commands in a regular basis. To create alias
list you should create or edit ~/.bashrc. Here is how you do it.

Open the Terminal.app

cd
vim .bashrc

If the file exists you can scroll down to the bottom and press i to insert some aliases

alias la = 'ls -al'
alias ll = 'ls -l'
alias dfile = 'rm -f'
alias dfolder = 'rm -rf'
alias md = 'mkdir'
alias v = 'vim'
alias c = 'clear'

Hit Esc, type :wq and hit Return to exist Vim editor.
The above aliases to be binding, you have to start the Terminal.app

If you want to check the existing aliases, type alias and hit Return.
You can temporarily deactivate an alias using unalias command.

Eg. unalias la would temporarily deactivate la alias that I previously created.

Share and Enjoy:
  • Digg
  • del.icio.us
  • MisterWong
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati

Alternative to multiple tabs in OS X Terminal.app – screen

Unfortunately, the Terminal.app comes with OS 10.4 doesn’t have the tab functionality. Most of the Mac users who like to work on several instances of shell without cluttering the desktop use iTerm. However, there is a nother alternative to this called screen. screen is a powerful shell command which lets you open multiple instances of shell in a single window. You can use default keyboard shortcuts to navigate between different instances or you can even define your own.

To make use of the screen command you should first create a configuration file and save it in user directory. Here’s how.

  • Open Terminal.app from Applications/Utilities
  • Type cd and press return
  • To create a config file using vim editor, type vim .screenrc and press return.
  • Press i and enter the following text
  • hardstatus alwayslastline
    hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]'

    screen -t shell1    0
    screen -t shell2    1
    screen -t shell3    2
  • Press escape, type :wq and press return to save the file and return to shell prompt. Restart the Terminal.App to bind the config file. Now when you type screen and press enter it should show you several terminal instances. You can navigate to the next instance by pressing Ctrl + a and n. Some of the common keyboard shortcuts are listed below.
  • screen

    Screen also lets you issue shell commands when executing screen. The standard syntax you should add to the config file looks like,

    screen -t <screenname> <screenNumber> <shell command>

    eg.

    screen -t shell2 1 'ps aux'

    As mentioned previously, each keyboard command consists of a C-a followed by one other character. For your convenience, all commands that are bound to lower-case letters are also bound to their control character counterparts (with the exception of C-a a; see below). Thus, both C-a c and C-a C-c can be used to create a window.

    The following table shows the default key bindings:

    C-a ‘
    C-a “

    (select)
    Prompt for a window identifier and switch. See section Selecting a Window.

    C-a 0…9
    (select 0…select 9)
    Switch to window number 0…9. See section Selecting a Window.

    C-a C-a
    (other)
    Toggle to the window displayed previously. See section Selecting a Window.

    C-a a
    (meta)
    Send the command character (C-a) to window. See escape command. See section Command Character.

    C-a A
    (title)
    Allow the user to enter a title for the current window. See section Naming Windows (Titles).

    C-a b
    itemx C-a C-b (break)
    Send a break to the tty. See section Break.

    C-a B
    (pow_break)
    Close and reopen the tty-line. See section Break.

    C-a c
    C-a C-c

    (screen)
    Create a new window with a shell and switch to that window. See section Screen Command.

    C-a C
    (clear)
    Clear the screen. See section Clear.

    C-a d
    C-a C-d

    (detach)
    Detach screen from this terminal. See section Detach.

    C-a D D
    (pow_detach)
    Detach and logout. See section Power Detach.

    C-a f
    C-a C-f

    (flow)
    Cycle flow among `on’, `off’ or `auto’. See section Flow.

    C-a C-g
    (vbell)
    Toggle visual bell mode. See section Bell.

    C-a h
    (hardcopy)
    Write a hardcopy of the current window to the file “hardcopy.n”. See section hardcopy.

    C-a H
    (log)
    Toggle logging of the current window to the file “screenlog.n”. See section log.

    C-a i
    C-a C-i

    (info)
    Show info about the current window. See section Info.

    C-a k
    C-a C-k

    (kill)
    Destroy the current window. See section Kill.

    C-a l
    C-a C-l

    (redisplay)
    Fully refresh the current window. See section Redisplay.

    C-a L
    (login)
    Toggle the current window’s login state. See section Login.

    C-a m
    C-a C-m

    (lastmsg)
    Repeat the last message displayed in the message line. See section Display Last Message.

    C-a M
    (monitor) Toggle monitoring of the current window. See section Monitoring.

    C-a SPC
    C-a n
    C-a C-n

    (next)
    Switch to the next window. See section Selecting a Window.

    C-a N
    (number)
    Show the number (and title) of the current window. See section Number.

    C-a p
    C-a C-p
    C-a C-h
    C-a BackSpace

    (prev)
    Switch to the previous window (opposite of C-a n). See section Selecting a Window.

    C-a q
    C-a C-q

    (xon)
    Send a ^Q (ASCII XON) to the current window. See section XON and XOFF.

    C-a r
    C-a C-r

    (wrap)
    Toggle the current window’s line-wrap setting (turn the current window’s automatic margins on or off). See section Wrap.

    C-a s
    C-a C-s

    (xoff)
    Send a ^S (ASCII XOFF) to the current window. See section XON and XOFF.

    C-a t
    C-a C-t

    (time)
    Show the load average and xref. See section Time.

    C-a v
    (version)
    Display the version and compilation date. See section Version.

    C-a C-v
    (digraph)
    Enter digraph. See section Digraph.

    C-a w
    C-a C-w

    (windows)
    Show a list of active windows. See section Windows.

    C-a W
    (width)
    Toggle between 80 and 132 columns. See section Window Size.

    C-a x
    C-a C-x

    (lockscreen)
    Lock your terminal. See section Lock.

    C-a z
    C-a C-z

    (suspend)
    Suspend screen. See section Suspend.

    C-a Z
    (reset)
    Reset the virtual terminal to its “power-on” values. See section Reset.

    C-a .
    (dumptermcap)
    Write out a `.termcap’ file. See section Write out the window’s termcap entry.

    C-a ?
    (help)
    Show key bindings. See section Help.

    C-a C-\
    (quit)
    Kill all windows and terminate screen. See section Quit.

    C-a :
    (colon)
    Enter a command line. See section Colon.

    C-a [
    C-a C-[
    C-a ESC

    (copy)
    Enter copy/scrollback mode. See section Copying.

    C-a ]
    C-a C-]

    (paste .)
    Write the contents of the paste buffer to the stdin queue of the current window. See section Paste.

    C-a {
    (history)
    Copy and paste a previous (command) line. See section History.

    C-a >
    (writebuf)
    Write the paste buffer out to the screen-exchange file. See section Screen-Exchange.

    C-a <
    (readbuf)
    Read the screen-exchange file into the paste buffer. See section Screen-Exchange.

    C-a =
    (removebuf)
    Delete the screen-exchange file. See section Screen-Exchange.

    C-a _
    (silence)
    Start/stop monitoring the current window for inactivity. See section Silence,

    C-a ,
    (license)
    Show the copyright page.

    Have fun!

    Share and Enjoy:
    • Digg
    • del.icio.us
    • MisterWong
    • Reddit
    • Slashdot
    • StumbleUpon
    • Technorati

    How to create a symbolic link

    Creating a symbolic link is useful when you want to point to an application, a file or folder located in a different location.

    Usage:

    ln -s /Original/Folder/Path /Destination/Folder/Path

    Example:

    ln -s /Volumes/ExHDD/MyPrograms /Users/John/Desktop/Pro
    Share and Enjoy:
    • Digg
    • del.icio.us
    • MisterWong
    • Reddit
    • Slashdot
    • StumbleUpon
    • Technorati

    How to access HFS+ formatted HDD from a Windows PC?

    There are several ways you can access a Mac HDD from Windows PC. If you have a Mac and a PC you can activate the File Sharing in System Preferences on your Mac and you are ready to go. The Mac should appear under network. You can make the process easier by mapping the network drive.

    If you don’t have access to a Mac but want to connect to a HFS+ formatted HDD, there are two possibilities.

    1. Read only access
    2. Download the HFSExplorer from catacombae. To mount the HFS+ partition you should select the “Run HFSExplorer in Administrator mode”. As mentioned above this tool can only read.

    3. Read and write access
    4. MacDrive7(MacDrive 8 is coming soon) is a commercial software that can both read and write a HFS+ formatted HDD. You can download a trial version from their website.

    Share and Enjoy:
    • Digg
    • del.icio.us
    • MisterWong
    • Reddit
    • Slashdot
    • StumbleUpon
    • Technorati

    Synchronize folders using rsync and ssh

    Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

    Rsync finds files that need to be transferred using a “quick check” algorithm (by default) that looks for files that have changed in size or in last-modified time. Any changes in the other preserved attributes (as requested by options) are made on the destination file directly when the quick check indicates that the file’s data does not need to be updated.

    By using combining rsync with ssh it is really easy to securely synchronize folders.

    To sync a local folder with a remote folder, use the following command.

    rsync -avz -e ssh user@remoteaddress:/remotepath/ /localpath

    Eg.

    rsync -avz -e ssh me@remote.com:/home/me/Documents /User/john/Documents
    Share and Enjoy:
    • Digg
    • del.icio.us
    • MisterWong
    • Reddit
    • Slashdot
    • StumbleUpon
    • Technorati

    Shutdown your Mac using a terminal command

    The shutdown command comes in handy if you want to shutdown or reboot your Mac at a specific time. Here are some of the examples. You should be a super user to use these commands.

    sudo shutdown [options] when [message]

    Some examples.
    Shutdown immediately:

    sudo shutdown -h now

    Reboot immediately:

    sudo shutdown -r now

    Shutdown at 9 pm:

    sudo shutdown -h 21:00

    Shutdown in 5 minutes:

    sudo shutdown -h +5

    Restart immediately

    sudo reboot

    Shutdown immediately

    sudo halt
    Share and Enjoy:
    • Digg
    • del.icio.us
    • MisterWong
    • Reddit
    • Slashdot
    • StumbleUpon
    • Technorati

    Setup a secure ftp server for remote access on OS X

    Recently quite a number of forum members asked about how to transfer large file between remote locations. The online services such as DropBox and Wuala do a good job but if you already have a Mac or a Linux machine, it is so much easier and also secure to setup your own FTP (File Transfer Protocol) server using vsftpd (Very Secure File Transfer Protocol Daemon). In this article I will try to guide you through the entire setup process. Lets get started, shall we?

    1. First you need to install the vsftpd using Mac Ports. Open the Terminal.app, enter the following command and hit Enter. If you don’t have Mac Ports installed, get it from here.
    2. sudo port install vsftpd
    3. Now you have to create a vsftpd.config file which defines the rules to secure your ftp server. Fortunately, when you install vsftpd using Mac Ports, it will create a sample config file at /opt/local/etc/ directory. Use the following command to create a config file from the sample file.
    4. sudo cp /opt/local/etc/vsftpd.config.sample /opt/local/etc/vsftpd.config
    5. Open the vsftpd.config file on any editor and make the following changes.
    6. sudo vim /opt/local/etc/vsftpd.config

      To deny access to anonymous users, activate
      anonymous_enable=NO

      To allow local users to access their home directories
      local_enable=YES

      Add a welcome message
      ftpd_banner=Welcome to my FTP service!

      Lock the users in their root directories
      chroot_local_user=YES

      There are several other settings you could activate/deactivate on the config file. Do as it fits.

    7. To run the server, use the following command
    8. sudo /opt/local/sbin/vsftpd

      If you have done everything correctly so far the server should be up and running.

    9. To do an initial test try the following command in a separate tab.
    10. ftp 192.168.1.2

      Replace the ip address with your local ip address.
      This should ask you for a user name and password. Try the user name and the password you use for log-in to your Mac.

    11. Next step is to enable users to access your newly setup FTP server from a remote location. For this you need a service such as DynDNS or No-IP. You can sign-up for a free account with both providers. Once the registration is completed, go ahead and add a new host as shown in the following example.
    12. dyndns

      Do not forget to activate the service.

      If you have done everything correctly, you should be able to connect to the newly set up ftp server from any remote location.

      In case if you have a router in your home network don’t forget to do a port forward.

      That’s all. ;)
      Let me know how it went.

    Share and Enjoy:
    • Digg
    • del.icio.us
    • MisterWong
    • Reddit
    • Slashdot
    • StumbleUpon
    • Technorati