Macos 如何从bash脚本中找到当前的osx终端主题
在bash脚本中,我需要知道当前的OSX终端主题是什么。如何做到这一点Macos 如何从bash脚本中找到当前的osx终端主题,macos,bash,scripting,terminal,themes,Macos,Bash,Scripting,Terminal,Themes,在bash脚本中,我需要知道当前的OSX终端主题是什么。如何做到这一点 我检查了env命令的输出,但没有找到任何内容。对于每个shell,您不能。您可以获得默认设置: defaults read com.apple.Terminal "Default Window Settings" 或新窗口设置: defaults read com.apple.Terminal "Startup Window Settings" 我们可以使用AppleScript从bash shell中检索最前面的终端窗
我检查了env命令的输出,但没有找到任何内容。对于每个shell,您不能。您可以获得默认设置:
defaults read com.apple.Terminal "Default Window Settings"
或新窗口设置:
defaults read com.apple.Terminal "Startup Window Settings"
我们可以使用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
将“基本”替换为您希望采用的配置文件的名称
这些命令将应用于Terminal.app的当前/最前面选项卡或窗口
我还编写了一个脚本,该脚本将根据是否提供配置文件名来获取/设置配置文件:。用法示例:
# Gets profile name
> term-profile
Basic
# Sets profile to Basic
> term-profile Basic
>
直接在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的一些细节
愉快地编写bash脚本运行在单个选项卡、窗口中。那么脚本想要知道的主题的名称是什么。有什么方法可以获得“当前”设置吗?