[英]Open new terminal at in current directory
Using bash on MacOS Mojave, I want to open a terminal in the current directory and execute a command: 我想在MacOS Mojave上使用bash,我想在当前目录中打开一个终端并执行命令:
#!/bin/bash
osascript -e 'tell application "Terminal"' -e 'do script "./something_to_run"' -e 'end tell'
The code above opens a new terminal window, but it does so at the root directory and not the directory the script above executed in. I guess I should use pwd
somehow, but I am not sure how. 上面的代码打开一个新的终端窗口,但它是在根目录而不是上面的脚本在其中执行的目录中进行的。我想我应该以某种方式使用
pwd
,但是我不确定如何使用。
How can I fix this? 我怎样才能解决这个问题?
osascript -e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down'
osascript -e 'tell app "Terminal" to do script "./script.sh" in window 1'
I found these commands from a GitHub Gist . 我从GitHub Gist找到了这些命令。 First command opens a tab in your existing terminal window and the second says do the script in that tab.
第一个命令在您现有的终端窗口中打开一个选项卡,第二个命令说在该选项卡中执行脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.