【问题标题】:How to find all available fonts on OSX using the default shell如何使用默认 shell 在 OSX 上查找所有可用字体
【发布时间】:2019-12-19 17:42:20
【问题描述】:

我正在尝试使用 extendscript(一种专有的 ECMAScript 方言,但主要是 ≈ javascript)为 Adob​​e After Effects 编写脚本。我可以使用inbuilt commandsystem.callSystem() 使用默认(?)shell 执行命令,但我找不到一个bash 单行,或者我可以用来列出可用字体的AppleScript 命令。

有没有办法在 OSX 的命令行中获取所有字体?

【问题讨论】:

  • 试试这个:atsutil fonts -list。它似乎输出了两个列表——系统字体和系统字体系列——所以你必须按摩输出。
  • 我不是专家,但我想知道应用程序知道并可以使用的 已安装 字体与恰好包含字体并存在于文件系统,但应用程序不知道...只是一个想法。
  • @MarkSetchell 好点。我在想操作系统会知道已安装的字体,因此会有某种方式来查询已安装的字体。我只对应用程序可用的字体感兴趣
  • 看起来“字体书”可能是 Applescriptable...macscripter.net/viewtopic.php?id=41022

标签: bash macos fonts applescript extendscript


【解决方案1】:

从 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)

【讨论】:

  • 请问什么是 ASOC?请问我应该把这段代码放在哪里运行它?以及如何?
  • ASOC 只是 AppleScript Objective-C 的简写——使用 Objective C 对象和命令的 AppleScript——这是我编写的。您可以使用脚本编辑器应用程序中的第一个脚本,然后使用命令行或 shell 脚本中的第二个脚本。
【解决方案2】:

解决方案 1:AppleScript

tell application "Font Book" to set activeFontsList to name of every font family --- whose enabled is true

请注意,whose enabled is true 过滤器已被注释掉,因为它会大大降低查询速度。

解决方案 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"

相同的脚本,但单行:

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/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-24
    • 2016-09-22
    • 1970-01-01
    • 2011-10-16
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    相关资源
    最近更新 更多