Archive for the ‘terminal’ Category

Killing Finder or Dock (or any other mac OS X application)

Wednesday, March 11th, 2009

When an application in OS X is stalling on you and you have given up on regaining control of it, the best thing to do is kill it before it takes down your whole machine. Usually you would right click on the application icon in the Dock and choose the menu item “Quit” or “Force Quit” if available and that should do the trick.

Dock Menu When Right Clicking Application

Dock Menu When Right Clicking Application

Or you could click on the top left corner “apple” icon which will bring up a menu where you will see something called “Force Quit”. Choosing that option will open a small window with a list of the running applications which you can forcibly kill.

Force Quit Applications

Force Quit Applications

Sometimes though a key component of OS X fails on you which you don’t have an option to force quit like the above mentioned methods. I came to such a situation when the Dock froze on me the other day. It just would not come up at all. Today I had a similar situation when I had cover flow switched on in the finder while I was browsing an external hard drive that has 20 gigs of hundreds of subfolders inside hundreds of subfolders that contain thousands of photos. Cover flow could not handle this and it wouldn’t allow me to do antyhing else either. I had an application crunching data for the past 5 hours so restarting the machine was definitely not an option. I needed a way to cleanly kill Finder without destroying any other work going on. In situations like this you need to go beyond the GUI and directly to the terminal. Yes, I know, now that I am writing this article, I noticed that the “Force Quit” application actually has Finder as an option but being someone from a linux background I immediately go to Terminal for anything I need rather than look for GUI solutions.

What you need to do is find the PID (Process ID) of the application you need to kill. To do this, type the following in Terminal:

ps aux | grep Finder

The result of that command will be something like:

sergemadenian   131 97.1 25.9  1213744 542124   ??  R    Fri12PM  54:49.70 /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder -psn_0_40970
sergemadenian  3932   0.1  0.0   590472    192 s000  R+   10:07PM   0:00.00 grep Finder

“ps aux” is the command that prints out all the currently running processes from all users. ” | grep Finder” will restrict the results of the “ps” command to show only the lines that contain the word “Finder”.

From the above result you can tell that the Finder application is question is the first line and I have set the PID in Bold and red “131″. You can also tell that this process is struggling because immediately after the pid we see the CPU and memory usage which in this case is “97.1 25.9″ (those are percentages).

Now that we know the PID (131) all you need to do is run the command:

kill -9 131

“-9″ tells the OS to kill immediately. That took care of the offending Finder window and I noticed that a new Finder process had been kicked off by the OS. If a new process had not automatically been kicked off, I would have had to start it manually by running the command that was running before which I’ve marked in blue and bold ”

Same process applies to any application including the Dock. All you need to do is find the specific PID by changing what you filter with grep. For the Dock as an example, you will need to run:

ps aux | grep Dock

Remember that the PID is not a universal number (that is your Finder application will not have 131, even my computer will have a different PID for Finder when I restart it) so you need to always find the unique PID running at the time.

Using Java 1.6 (java 6) on Mac OSX (Edit: For Development Only)

Thursday, October 16th, 2008

Recently we’ve started using some packages in java that require us to use Java 1.6 (sometimes refered to as Java 6. Which one is it java, 1.6 or 6? We’re at war, pick a side!). If you have Mac OSX leopard then you should have both 1.5 and 1.6 installed on the system but by default 1.5 is used.

To check which version is being used when you log in, open up terminal and type:

java -version
You should see something like:

java version “1.5.0_16″
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)
Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)

To switch this to use 1.6 instead, you need to add the following to your .bashrc:

alias java=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Commands/java
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/

Remember to either exit your terminal and start a new session or just run the command:

source ~/.bashrc

for the changes to take effect.

Turn on syntax highlighting in VI on Macbook

Friday, June 15th, 2007

If you installed the developer tools on macbook as I did the moment I started it up, you should have VI on your system. I’m used to the syntax highlighting in VI but macs don’t have that enabled by default. You could just run the command:

:syntax onÂ

And immediately you’ll have syntax highlighting. The issue with this method though is that once you quit VI and open a new file, there will be no syntax highlighting and you will need to run the command again.

To have highlighting always enabled, just create or edit the file $HOME/.vimrc and add the following line to it:

:syntax on

Open a new file in VI to test and you should see your code in color.

Sourcing .bashrc at terminal startup (Mac OS X)

Thursday, June 14th, 2007

I discussed this briefly in my post on installing subversion but I think it deserves a post of it’s own mostly because I forgot how to accomplish this task and couldn’t find it again as easily.

If you are a windows user, .bashrc may be completely unfamiliar to you. It’s basically a file that you place in your home directory (that would be /Users/your_username on macbook) where you can define environment variables and command aliases. You can actually run any bash command int hat file since it would be a bash script that runs on startup.

The macbook though does not startup with that file sourced automatically. You need to configure it to get it working.

Mac OS X sources /etc/profile when terminal starts off, so all you need to do is add the following line to your /etc/profile file:

[ -r $HOME/.bashrc ] && source $HOME/.bashrc

This will source your ~/.bashrc file on startup and the next time you open terminal all your commands in .bashrc will have run.

I like to have the following settings in my .bashrc:

alias ll=’ls -l’

This line creates an alias for the command ll (that’s two Ls). This should be familiar to many linux users. ls -l is probably the most typed command and shortening it to ll makes life mch easier.

export PS1=”\[\e[1;34m\]\u@\H:\[\e[0m\]\[\e[1;36m\]\w\[\e[0m\]\n\[\e[1;34m\]\t->\[\e[0m\]“

This is my favorite configuration for the prompt on the command line. It will produce the following:

smadenian@serge-madenians-computer.local:/usr/local/maven-2.0.4/bin
11:36:38->

What I like about this prompt is that it shows me which computer I’m working on (good when you ssh into other servers/machines). It shows me my full path. It is plit to two lines (anyone who has gone down a long path and reached the end of the line while typing a command will appreciate that). And finally there’s the time which helps me know when I ran a command and when it finished.

I’ve also created other aliases and path configuration that may not be as useful as the above mentioned items.