Open URLs and Applications from Terminal and Ruby Scripts

Did you know you can open applications directly from the command line in Terminal?  The command is open

To open a url in the browser from the command line, use

open http://www.apple.com/

You don’t need quotes around the url. This will use the default browser on your machine.

The line

open /Applications/

will open the Applications folder in Finder.

To open a specific application, use the path to that application followed by the .app extension.

open /Applications/Airdroid.app

(Airdroid is a great application for transmitting files from your computer to phone wirelessly.)
If you want to open Sublime Text from the terminal, you can use the command subl

subl .

Will open the current directory in Sublime Text.

If you’re writing a ruby script, use these commands instead:

system("open", "http://stackoverflow.com/")
system("open", "/Applications/Adobe\ Illustrator\ CS6/Adobe\ Illustrator.app")

credit here

Advertisements

Remove a non-empty directory in Terminal

I love using the command line like a ninja, but its also really annoying when you don’t know the exact right command or option.  I was trying to delete a directory the other day, and kept getting the annoying error “Directory not empty”

Screen Shot 2013-08-03 at 11.37.20 AM

So here is how to fix it.  I found the answer here, as I will outline below.

Use the ‘-R’ option with the ‘rm’ command to delete an empty directory.  If the directory has relatively few files, I recommend using the ‘-i’ flag, as that will ask you to confirm each file to delete.   See the screenshots below for an example:

Screen Shot 2013-08-03 at 11.41.14 AMHope you found this useful!