Are you frustrated with running the same scripts again & again before resuming your work? Here is a simple solution to change that.
We often develop complex applications which require a certain amount of basic setup to begin development on every occasion.
For instance, I recently started working on a react-native project where I had to develop a mobile application with a backend on Express.js and MongoDB. I generally use iTerm 2 on my M1 MacBook as my go-to application for terminal usage.
In every instance whenever I wished to resume my work on a daily basis, I had to perform a few routine tasks to set up my development environment as follows:
#Terminal1
cd <BackendProjectFolder>
npm run start
#Then open the MongoDB Compass Application
#Terminal2
cd <ApplicationProjectFolder>
npm run android
#Then open the VSCode and navigate to project folder
After doing all these routine tasks every time I will be good to start my development. It might look small but there are developers who develop lots more things that require a large basic set-up to start their development.
Hence I decided to develop a script that would automate the above process for me!
I have developed an AppleScript that would run the necessary commands on multiple tabs as needed to set up my environment as needed to start my development in no time.
#!/bin/bash
osascript -e 'tell application "iTerm2"
set newWindow to (create window with default profile)
tell current session of newWindow
write text "cd /Users/akellaniranjan/Desktop/Hypr-API-1
npm run start"
end tell
tell current window
create tab with default profile
tell current session
write text "open $MONGODB_COMPASS
open $VSCODE"
end tell
end tell
tell current window
create tab with default profile
tell current session
write text "cd /Users/akellaniranjan/Desktop/Hypr-Mobile_App
npm run android"
end tell
end tell
end tell'
tell application "iTerm"
set newWindow to (create window with default profile)
tell current session of newWindow
write text "cd /Users/akellaniranjan/Desktop/<BackendProjectFolder>
npm run start"
end tell
tell current window
create tab with default profile
tell current session
write text "open $MONGODB_COMPASS
open $VSCODE"
end tell
end tell
tell current window
create tab with default profile
tell current session
write text "cd /Users/akellaniranjan/Desktop/<FrontendProjectFolder>
npm run android"
end tell
end tell
end tell
#Add these two lines below the PATH variable at the beginning
export MONGODB_COMPASS=/Applications/MongoDB\ Compass.app
export VSCODE=/Applications/Visual\ Studio\ Code\ -\ Insiders.app
I added further functionality to run the above-developed script just using a keyboard shortcut from any application. This simplifies my workflow tremendously by reducing the time needed for me to set up the boring stuff through automation.
Note: Below instructions are given as of 25th April 2022, MacOSX. It may/may not vary, please kindly do refer to other sources for slight modifications.
If you found this article helpful please do share it with your peer developers to ease their workflows and embrace knowledge.
— Niranjan Akella
This article was first published here.