Creating a simple Automator app to launch a new instance of RStudio Desktop on macOS
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Introduction: how to open a second instance of RStudio Desktop on macOS
On macOS when RStudio Desktop is open it can be inconvenient to open a second (or third or fourth) instance of it.
If you left click the RStudio Desktop icon nothing happens. If you right click on the RStudio Desktop icon there is a convenient New RStudio Window. The problem with this is that by default if you have an RStudio project open the new RStudio window is also opened in that project. However, that can be overcome by opening the RStudio preference pane and in the first tab (General | Basic) deselecting the boxes relating to Restore most recently opened project at startup and Restore previousy open source documents at startup.
Alternatively, within RStudio Desktop we could select File | Open Project… but I’ve never found that very intuitive and somehow I’ve never got used to using RStudio’s command palette. If you have several directories configured as RStudio projects (with .Rproj files) that you’ve opened before you could open those from the top right project drop down menu or double click them from within Finder.
But let’s say we want an even more convenient way of doing this – an icon in the dock. Thanks to this Stackoverflow answer, it turns out that in a terminal we can issue the following open
command to achieve opening a new instance of RStudio Desktop (note RStudio Desktop needs to be installed in your Applications directory for this to work).
open -n -a RStudio.app
Making an Automator app to open a new instance of RStudio Desktop
macOS comes with Automator, open that from your Applications directory.
Then select File | New and select Application and click Choose.
Then from the left most menu select Utilities and double click Run Shell Script.
In the main window on the right, leave the shell as zsh and replace the cat
text in the box with the open
command above.
Then press Cmd + S or File | Save and save your application in your Applications folder. Give the app a distinct name such as RStudio-new-instance.app or whatever you prefer and then quit Automator.
Next we would like our app to have a nice icon.1
- First download a nice icon from say this repo of logos kindly designed for RStudio (I chose the dark one).
- Then navigate to the our new app in Finder and press Cmd + I.
- Then drag the .icns file onto the icon in the top left corner of the info box. And tada your app will now use this icon!
And you can even drag the app from Finder onto your dock from where you can simply click the icon to open as many instances of RStudio Desktop as you like.
And because the new application is in our Applications directory it is found by Alfred (and hopefully Raycast).
Summary
We have created an Automator application which runs a shell script to open a new instance of RStudio Desktop. We have then given this application a new icon and we have placed this on our dock.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.