Tuesday, 30 July 2013

How to Launch & Run Multiple Instances of Any Application in Mac OS X

Run Multiple Instances of Any Application in Mac OS X
You can run multiple instances of any application in Mac OS X with a little command line magic. Using the ‘open’ command to launch GUI apps from the Terminal, we can run a new instance of any app, even if it is already running.
In the simplest form, we just point open to the application with the -n flag. For a practical example, we’ll use the Safari browser:
open -n /Applications/
This will launch a new instance of Safari, even if Safari is already open. You can repeat this command to launch as many instances of the app that you want running.
Instead of repeating the command over and over again though, let’s make it even easier to launch multiple instances of the app though. What if you want to launch five new instances of Safari? Assuming you’re using bash, we’ll use this command:
n=5 ; for (( c=1; c<=n; c++)) ; do open -n /Applications/ ; done
Now that's a bit of a complicated string to type over and over again, so we'll make it easier by creating an alias in your .bash_profile:
First you need to open .bash_profile in a text editor, nano is nice and easy:
nano ~/.bash_profile
Now paste this into a new line , just make sure everything is on a single line:
alias safarix5='n=5 ; for (( c=1; c<=n; c++)) ; do open -n /Applications/ ; done'
Save changes to .bash_profile by hitting Control+O and hitting return
I named the alias 'safarix5' for Safari X 5, since that string launches 5 instances of Safari, but you can call it whatever you want. If you wanted to run Safari in 10 different instances, it's just a matter of changing the variable 'n' like so:
alias safarix10='n=10 ; for (( c=1; c<=n; c++)) ; do open -n /Applications/ ; done'
You can change the application to anything you want, just remember that each running instance of an app consumes the full amount of resources for that app. Web and app developers should be particularly happy with this trick, but there are plenty of other uses as well.


Post a Comment

Back to top!