osascript 打开termainal新页
How to programmatically open a new terminal tab or window
I stumbled across this while trying to calculate some configuration options and open multiple terminal windows at once to run multiple Node services.
There are two ways to programmatically open a new terminal window or tab on a mac, depending on whether or not you use iTerm or the default Terminal program. I’ll share both, with a brief explanation on how it works.
Open a new window in iTerm2
Open a new tab in iTerm2
Open a new window in Terminal
`osascript` is a command to run AppleScript. They can be enclosed in a string or in a file. The `-e` flag tells it that you are passing a command as a string. The weird rules with shell string escaping make it a little challenging to do anything too complicated with this passed in command. There are many more options you can explore with `man osascript`.
Pass arguments to AppleScript file
One final interesting tip. You can save avoid the quote mess with the `-e` flag by saving your AppleScript in a separate file and passing in an argument:
Then in the AppleScript file itself you can access the arguments with a `item 1 of argv` syntax like so:
I don’t know a whole lot about AppleScript but have heard it can automate just about anything related to your mac. Perhaps I’ll dedicate a future blog post to some interesting use for this.
交流QQ号:1175372067
电话:18551717618(同微信)
元几科技.软件3部
迈开步伐去探索
南京元几科技有限公司
元几社区: https://www.cnblogs.com/colin-vio
元几官网: http://www.yuanji.tech
-----------------------------------------------------------------------------