如何使用默认 shell 在 OSX 上查找所有可用字体
How to find all available fonts on OSX using the default shell
我正在尝试使用 extendscript(一种专有的 ECMAScript 方言,但主要是 ≈ javascript)为 Adobe After Effects 编写脚本。我可以使用 inbuilt command system.callSystem()
来执行使用默认值(?)shell 的命令,但我找不到 bash 单行或 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)
解决方案 1:AppleScript
tell application "Font Book" to set activeFontsList to name of every font family --- whose enabled is true
Note that the whose enabled is true
filter is commented out because it slows down the query considerably.
解决方案 2:AppleScript & Bash
您可以从 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"
相同的脚本,但 one-liner:
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"
解决方案 3: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/。
我正在尝试使用 extendscript(一种专有的 ECMAScript 方言,但主要是 ≈ javascript)为 Adobe After Effects 编写脚本。我可以使用 inbuilt command system.callSystem()
来执行使用默认值(?)shell 的命令,但我找不到 bash 单行或 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)
解决方案 1:AppleScript
tell application "Font Book" to set activeFontsList to name of every font family --- whose enabled is true
Note that the
whose enabled is true
filter is commented out because it slows down the query considerably.
解决方案 2:AppleScript & Bash
您可以从 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"
相同的脚本,但 one-liner:
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"
解决方案 3: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/。