如何在Bash脚本中查找当前的OSX终端主题

4
在bash脚本中,我需要知道当前的OS X终端主题是什么。如何实现?
我检查了env命令的输出,但没有发现任何内容。

一个Bash脚本只能在单个选项卡或窗口中运行。那么脚本想要知道的主题名称是什么? - american-ninja-warrior
3个回答

4
我们可以使用 AppleScript 在 bash shell 中检索最前面终端窗口的配置文件名称:
echo 'tell application "Terminal" to return name of current settings of first window' | osascript

我们可以类似地设置个人资料:
echo 'tell application "Terminal" to set current settings of first window to settings set "Basic"' | osascript

将“Basic”替换为您希望采用的配置文件名称。

这些命令将应用于Terminal.app的当前/最前面的标签页或窗口。

我还编写了一个脚本,根据提供的配置文件名称来获取/设置配置文件:https://github.com/starbase527/dotfiles/blob/master/local/bin/term-profile。例如用法:

# Gets profile name
> term-profile
Basic
# Sets profile to Basic
> term-profile Basic
>

2
在每个 shell 的基础上,你不能这样做。但你可以获取默认设置:
defaults read com.apple.Terminal "Default Window Settings"

或者是新窗口设置:

defaults read com.apple.Terminal "Startup Window Settings"

有没有办法获取“当前”的设置? - american-ninja-warrior
这应该是最好的回答。 - OzzyCzech

0

在zsh中,您可以像这样获取当前的Terminal.app主题:

CURRENT_THEME=$(osascript -e 'tell application "Terminal" to return name of current settings of first window')
echo $CURRENT_THEME

通过这些方法以及一些AppleScript知识,你可以获取Terminal.app的一些细节信息。

编程愉快!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接