The OSX “open” command line tool is very useful.  Use it to launch a URL or point to a folder and the web browser or Finder pops up automatically.  But what about when you want to launch a particular app to handle a resource you provide?  It can do that as well.  Easily.

In this example I’m setting up my environment to launch several Windows remote desktop client sessions using the wonderful CoRD application.  The idea is that I can put the CoRD app in a folder with a shell script and have an easily transportable launcher package to give to others – without them having to install a RDP client, etc.

Because I’m not install the CoRD application globally, the RDP protocol doesn’t get associated with the app.  Therefore, when using the open command I need to explicitly tell it what application to launch it with, using the “-a” flag:

 open -a /User/tyler/CoRD.app/Contents/MacOS/CoRD rdp://winserver1:3389

The benefit to using the open command here is that it won’t launch new CoRD instances, but will add them as sessions to the existing one.  Likewise, open will start the process and return you to the command line – so you can list several open statements in a script and it will run them all without having to do any funky backgrounding step.

Thanks to this old OSXDaily post for pointing me in the right direction.  I had given up on the command because I didn’t realise there were more options.  Next time I’ll read the manual first!

 

 

About Tyler Mitchell

Director Product Marketing @ OmniSci.com GPU-accelerate data analytics | Sr. Product Manager @ Couchbase.com - next generation Data Platform for System of Engagement! Former Eng. Director @Actian.com, author and technology writer in NoSQL, big data, graph analytics, geospatial and Internet of Things. Follow me @1tylermitchell or get my book from http://locatepress.com/.