简体   繁体   English

在当前目录中打开新终端

[英]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.

相关问题 如何在终端中打开应用程序并传递当前工作目录? - How to open an app in terminal and passing the current working directory? 使用git提示符命令在当前文件夹中打开gnome terminal new选项卡 - Open gnome terminal new tab in current folder with git prompt command 在“ ssh目录”中打开新的终端窗口(Mac OS Yosemite) - Open a new Terminal window in “ssh directory” (Mac OS Yosemite) ConEmu + Ubuntu Bash:如何在当前目录中打开新选项卡 - ConEmu + Ubuntu Bash: How to open new tab in current directory Terminal.app中的新选项卡无法在同一目录中打开/ bash失败(Mountain Lion) - New tab in Terminal.app does not open in same directory/bash fails (Mountain Lion) Python:更改终端当前目录并调用脚本 - Python: Changing terminal current directory and calling script 使用 python cli 工具更改当前终端的目录 - Change directory of current terminal with python cli tool 在bash终端窗口中显示当前目录名称 - Display the current directory name in bash terminal window 使用Node.js更改Bash终端的当前工作目录 - Change current working directory of bash terminal with Nodejs Bash脚本打开终端并cd到可变目录 - Bash script to open a terminal and cd to a variable directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM