How to run a command on open terminal via shortcut I am developing using electron on macOS. After making changes we need to run the terminal command npm start to run the app.

I would like to create a shortcut on macOS so that it simply switches focus on the terminal and runs the command.

Currently I'm using this, but it loads a new terminal window:

on run {input, parameters}

    tell application "Terminal"
        reopen
        activate
        do script "npm start"
    end tell

end run


I can't initiate a new terminal for this as the command has to be run from the current project folder to start it.

Any help in right direction would be appreciated.
Found the answer to this query so wanted to share.

The problem with the code in question was that it was opening the new temrinal window. 

The solution was th prevent it from doing that by running the code in already open window, by mentioning the window 1 in it like this:

tell application "Terminal"
    do script "npm start" in window 1
end tell


We can also use keycode and keystroke technique discussed here: https://stackoverflow.com/q/1870270/953566 too, however that was too lengthy and complicated, but can be useful in someones situation.