Force Delete in Mac OS X

Sometimes you want to delete a file in OS X and it’s locked:

It may be used by another application or maybe you don’t have the permission to delete the file.

Anyway, in this post I’ll show you a quick and easy way to overcome this problem. Do the following step by step:

1. Close all running applications.

2. Try deleting the file as root (in Terminal):

sudo rm -rf 'FILE PATH'

3. Try moving the file in Trash and Secure Empty it:

Hope it helps :)

Enable Colors in Mac OS X Terminal

No doubt, one of the most important apps in Mac is Terminal. You can do almost everything in text mode and of course you do this a lot.

Unlike many Linux distributions, OS X Terminal is really boring since it doesn’t support colors by default. Good news, you can easily enable colors by doing a few simple steps described below.

1. Download and install SIMBL:

SIMBL is a hack tool, helps third-party developer modify and add functionality to applications developed with Cocoa without access to the source code. Later we will use a SIMBL plugin to add color support to Terminal. Download and install it.

2. Install TerminalColours plugin:

After you installed SIMBL, you’ll need to install a plugin called TerminalColours. get TerminalColours-SL-64bit.zip here and unzip it to “/Library/Application Support/SIMBL/Plugins”.

Edit .bash_profile

Now you need to edit your .bash_profile file to enable color support.
Open ~/.bash_profile in your desired editor and add these lines:

export CLICOLOR=1;
export TERM="xterm-color"
export PS1="\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] "

save the file and QUIT Terminal if it’s running.

4. Install your desired color theme:

I use IR_Black. you can download it here. Just unzip the downloaded file and open IR_Black.terminal to install the theme.

Almost done. Your terminal is colorful now :) you can set IR Black theme to be the default by going to Shell > Use Settings as Default

Enjoy colorful terminal :)

Installing OpenCV on Mac OS X Snow Leopard

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. Version 2 ships with Python bindings and simply you can “import cv” module in Python after you’ve installed it.

The easiest way to install OpenCV on Mac is to use package management systems like port, fink or homebrew. They will automatically download, compile and install needed packages for you.

In this tutorial I’ll use brew, how ever you can use your preferred package manager.

Here is the short explanation of the installation process (every thing will be done on Terminal.app)

1. Install brew package manager. (instructions here)
2. Update brew formulas:

brew install git
brew update

3. Install opencv:

brew install opencv

and brew will automatically installs CMake and checks out opencv repository, Builds and installs it.

Note that you should edit your PYTHONPATH to make opencv working with Python. I wrote a simple script to do this automatically for Python 2.6 (Also brew should be installed on it’s default location).

RND=/tmp/$RANDOM
PYTHONPATH=`echo $PYTHONPATH | sed -e 's/\/usr\/local\/lib\/python2.6\/site-packages\/://g'`
cat ~/.bash_profile | grep -Ev "PYTHONPATH" > $RND
echo export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:"'$PYTHONPATH' >> $RND
mv $RND ~/.bash_profile

Just copy the script above and type:

pbpaste | sh

Close the Terminal and reopen it.

Now you can simply open your Python interpreter and type “import cv”.

Done. :)

Installing Eric5 on Mac

Eric IDE is a Cross-Platform Python and Ruby IDE, written in Python based on Qt toolkit. It looks really nice and powerful.

Recently I tried to install it on my Mac and had some troubles. Finally I managed to make it running and now I’d like to make a step-by-step installation tutorial:

1. Install Python 3:

Download and install Python 3.

2. Install GCC Compilers:

You will need GCC compilers to compile some source packages. The easiest way to install them is to Install XCode. You can download it here or install it from your OS X installation DVD.

3. Install Qt SDK:

Download Qt SDK for Mac. The installation process is pretty simple and straightforward.

4. Install SIP, PyQt4 and QScintilla2:

First, Grab SIP Linux, UNIX, MacOS/X source, PyQt4 MacOS/X source and QScintilla2 Linux, UNIX, MacOS/X source and extract them all in a directory. It’s also a good idea to rename the directories to something more comfortable:

Then open a terminal window and navigate into the path you’ve extracted source packages before, and execute the following commands:

cd sip-4.12
python3 configure.py --arch i386
make
sudo make install

cd ../PyQt-4.8.2
python3 configure.py --use-arch i386
make
sudo make install

cd ../QScintilla-2.4.6/Qt4
qmake --spec macx-g++ qscintilla.pro
make
sudo make install

cd ../Python
python3 configure.py
make
sudo make install

5. Install Eric5:

Download Eric5 and extract it somewhere.
Open the Terminal and navigate into the directory you’ve extracted Eric5 before and execute the following command:

sudo python3 install.py

Congratulations :) Now you can open Eric5 IDE by executing eric5 (ex. in the Terminal).

Hope it helps.

Unix Commands in Windows with GnuWin

It’s really annoying that you can’t use Unix commands in windows… fortunately there is a project on SourceForge called GnuWin that provides ports of tools with a GNU or similar open source license, to MS-Windows. Installing GnuWin utilities it quite easy and straightforward:

First download GetGnuWin32 from here and run it.
Accept the license agreement and then extract it at your desired location.

Then open Command Prompt. use cd command to navigate into the path you’ve extracted GetGnuWin32 files before.

Type download and press enter.
It automatically starts to download needed packages for installing GnuWin32.

Finally type install “c:\gnuwin32″ to install it on c:\gnuwin32:

Congratulations, you have successfully installed GnuWin32.

But wait… after the installation process finishes, this prompt shows up:

Optional:

You can ^*append^* the bin subdir of your installation folder to your PATH:
i.e. C:\gnuwin32\bin
There are a few gnu conflicts with Windows utilities, so make sure to ^*append^*.
That way the windows utilities take priority (i.e. sort^).

Of course you can append bin subdir to your PATH environment variable permanently. but It’s safer and easier to make a shortcut to cmd.exe with path set to “c:\gnuwin32\bin”:

Create a new shortcut in your desired location. in the “Type the location of the item” text box, type:

cmd /k path=%path%;c:\gnuwin32\bin

before we continue making our shortcut, let me explain the command above:

cmd opens command prompt.

/k following by a command, executes the specified command and continues running.

path=%path%;c:\gnuwin32\bin simply appends c:\gnuwin32\bin to current path.

now Click next. Choose a name for your shortcut (ex. GnuWin32 Command Prompt) and then click Finish.

Your shortcut is ready to use but, whenever you open it, it changes the current directory to your %windir% (ex. C:\WINDOWS) which is a bit uncomfortable. to fix this, Right-Click on the shortcut and select Properties. In Properties window clear the “Start in: ” field and click OK.

Well done :) have fun.

VPN Auto Connect Script for Mac

One good thing about OS X is the AppleScript. It’s simple, powerful and useful. You can simply automate your tasks with it and make your life easier. A few month ago I wrote a VPN Auto Connect Script to keep my VPN connection alive and now I would like to share it :)

Open your desired Editor or use OS X AppleScript Editor(Application/Utilities/AppleScript Editor) and Paste the following code (note that you should change “VPN” to your connection name at line 4):

on idle
	tell application “System Events”
		tell current location of network preferences
			set myConnection to the service “VPN”
			if myConnection is not null then
				if current configuration of myConnection is not connected then
					connect myConnection
				end if
			end if
		end tell
		return 120
	end tell
end idle

Save the script as Application and check Stay Open:

Save Script as Application

And now, when you open VPN Auto Connect, It automatically dials the connection every 120 sec.

When you open the Application, it’s icon will be appeared on the dock which is a bit annoying. To solve this problem we’ll make it an agent:

Right-Click on the Application Icon and click Show Package Contents.

Open Contents/Info.plist (you will need XCode or another PList Editor to edit Info.plist file). Click Add Item, select “Application is agent (UIElement)” and check it:

Application is agent (UIElement)

Save the file and now your Application package should be ran with no icons on the dock.

You may want to add it to Login Items to make it open automatically at login. There are a few ways to do that but the most simple way is to drag the application into the dock, Right-Click on it and select Options/Open at Login, and finally Drag it off to remove it from the dock.

You can also download my script here. (Note that it only works if your connection name is VPN so you should edit vpn-auto-connect.app/Contents/Resources/Scripts/main.scpt to set the connection name).

That’s all folks :) hope you liked it.

Follow

Get every new post delivered to your Inbox.