我正在尝试使用extendscript(一种专有的ECMAScript方言,但主要是≈javascript)为Adobe After Effects编写脚本。我可以使用 内置命令
system.callSystem()
来使用默认(?) shell 执行命令,但我找不到 bash oneliner,或者我可以用来列出可用字体的 AppleScript 命令。
有没有办法在 OSX 命令行上获取所有字体?
在 AppleScript 中,您可以使用此 ASOC 代码来获取系统可用的所有字体或字体系列的名称:
use framework "AppKit"
set fontFamilyNames to (current application's NSFontManager's sharedFontManager's availableFontFamilies) as list
set fontNames to (current application's NSFontManager's sharedFontManager's availableFonts) as list
我不确定您想要哪一个,所以我包含了两者的代码。如果您想从 bash 访问此脚本,请使用
osascript
命令:
fontFamilyNames=$(osascript << SCPT
use framework "AppKit"
set fontFamilyNames to (current application's NSFontManager's sharedFontManager's availableFontFamilies) as list
return fontFamilyNames
SCPT)
tell application "Font Book" to set activeFontsList to name of every font family --- whose enabled is true
请注意,
过滤器已被注释掉,因为它会大大减慢查询速度。whose enabled is true
您可以像这样从 Bash 执行上面的 AppleScript:
#!/usr/bin/env bash
# Query the list of fonts with AppleScript.
font_list=$(osascript << SCPT
tell application "Font Book" to set activeFontsList to name of every font family --- whose enabled is true
SCPT)
# Convert the list to column and sort it.
font_list=$(echo $font_list | awk -e 'gsub(", ", "\n")' | sort -f)
# Display the list.
echo -e "$font_list"
# Display the list size.
echo -e "$font_list" | wc -l | xargs printf "\nFont count: %d\n"
相同的剧本,但一句台词:
font_list=$(osascript -e 'tell application "Font Book" to set activeFontsList to name of every font family --- whose enabled is true') && font_list=$(echo $font_list | awk -e 'gsub(", ", "\n")' | sort -f) && echo -e "$font_list"
fc-list
fc-list : family | sort -f
fc-list : family | wc -l | xargs printf "\nFont count: %d\n"
您可以在这里找到一些示例:https://www.geeksforgeeks.org/fc-list-command-in-linux-with-examples/.
对于那些正在寻找使用
fc-list
的 Bash 语句的人,您可以尝试以下操作:
fc-list | sed 's/.*:\s*\([^:]*\):.*/\1/' | tr ',' '\n' | sed 's/^[ \t]*//;s/[ \t]*$//' | sort | uniq