打开Qt Creator - Preferences - Environment - System - Terminal ,后年直接设置为自己想要使用的脚本即可。
这里提供两个脚本,一个是直接打开Iterm2的新窗口,一个是打开Iterm2的新标签页。
#! /bin/bash
# ugly escaping: for apple script \ and " need to be escaped, whereas %q takes care of all bash escaping
declare -a args
mydir=`pwd`
mydir=$(printf '%q' "$mydir")
mydir="${mydir//\\/\\\\}"
args[0]="cd ${mydir//\"/\\\"};"
for a in "$@" ; do
x=$(printf '%q ' "$a")
x="${x//\\/\\\\}"
args[${#args[@]}]="${x//\"/\\\"}"
done
mArgs=${args[@]:0}
osascript <<EOF
set cdScript to "$mArgs"
tell application "iTerm2"
set newWindow to (create window with default profile)
tell newWindow
select
set _session to current session
tell _session
write text cdScript
end tell
end tell
end tell
第二个是打开新标签页:
#! /bin/bash
# ugly escaping: for apple script \ and " need to be escaped, whereas %q takes care of all bash escaping
declare -a args
mydir=`pwd`
mydir=$(printf '%q' "$mydir")
mydir="${mydir//\\/\\\\}"
args[0]="cd ${mydir//\"/\\\"};"
for a in "$@" ; do
x=$(printf '%q ' "$a")
x="${x//\\/\\\\}"
args[${#args[@]}]="${x//\"/\\\"}"
done
mArgs=${args[@]:0}
osascript <<EOF
set cdScript to "$mArgs"
tell application "iTerm2"
tell current window to set tb to create tab with default profile
tell current session of current window to write text cdScript
end tell
注意⚠️:
一定要给脚本文件加上可执行权限,不然不会生效的!
sudo chmod +x newtab.sh
在此感谢
macos - How to change terminal in Qt Creator? - Stack Overflowhttps://stackoverflow.com/questions/44573054/how-to-change-terminal-in-qt-creatormacos - open new tab in iTerm and execute command there - Ask Different (stackexchange.com)
https://apple.stackexchange.com/questions/110778/open-new-tab-in-iterm-and-execute-command-there