SSブログ

FontBookを使わず、使用可能なフォントのリストを取得したい [AppleScript辞書はつくれるか?]

 

先日の使用できるフォントを取得したい件の続きとなりますが、

Font Bookを使わずにフォントを知るには、やっぱりシステムプロファイラーでしょうか?

 

 

do shell script "system_profiler SPFontsDataType ;"

 で、システムがらみのフォントのみの情報を取得します。しかし、結果は

 

Fonts:

 

    Times New Roman Bold.ttf:

 

      Kind: TrueType

      Valid: Yes

      Enabled: Yes

      Location: /System/Library/Fonts/Supplemental/Times New Roman Bold.ttf

      Typefaces:

        TimesNewRomanPS-BoldMT:

          Full Name: Times New Roman Bold

          Family: Times New Roman

          Style: ボールド

          Version: Version 5.01.4x

          Vendor: The Monotype Corporation

          Unique Name: Monotype:Times New Roman Bold:Version 5.01 (Microsoft)

          Designer: Monotype Type Drawing Office - Stanley Morison, Victor Lardent 1932

          Copyright: (c) 2006 The Monotype Corporation. All Rights Reserved.

          Trademark: Times New Roman is a trademark of The Monotype Corporation in the United States and/or other countries.

          Outline: Yes

          Valid: Yes

          Enabled: Yes

          Duplicate: No

          Copy Protected: No

          Embeddable: Yes

          ・

          ・

 と、フォントの雑多な情報が詳細に入手できます。(雑多?詳細?)

しかし、この中で欲しい情報は、ポストスクリプト名とディスプレイでの表記名(Full Name)の二つ。

そして、使用できるかの判断コード(Enabled)くらいでしょうか 

 

シェルスクリプトを使っているのだから、grepを使えば速そうなのだが、このままではポストスクリプト名の取得が難しい。

他の項目は(Full Name:)とか(Style:)や(Enabled:)といった項目名を抜き出してくれば良いのだが、ポストスクリプト名だけは、なぜか項目名が無い。

どうしよう?

これは幸いにも、ポスウトスクリプト名の一行前には必ず "Typefaces:" という文字が入っているので、それを利用しよう。

 

do shell script "system_profiler SPFontsDataType | grep -A2 -e 'Typefaces:' ;"

 

 

      Typefaces:

        TimesNewRomanPS-BoldMT:

          Full Name: Times New Roman Bold

--

      Typefaces:

        WeibeiSC-Bold:

          Full Name: Weibei SC Bold

--

      Typefaces:

        BMYEONSUNG-OTF:

          Full Name: BM YEONSUNG OTF

--

      Typefaces:

        AppleBraille-Pinpoint8Dot:

          Full Name: Apple Braille Pinpoint 8 Dot

--

          ・

          ・

          ・

ついでに、使用可判断コードも追加。

 

do shell script "system_profiler SPFontsDataType | grep -A2 -e 'Typefaces:' -e 'Enabled:' ;"

 

 

      Enabled: Yes

      Location: /System/Library/Fonts/Supplemental/Times New Roman Bold.ttf

      Typefaces:

        TimesNewRomanPS-BoldMT:

          Full Name: Times New Roman Bold

--

          Enabled: Yes

          Duplicate: No

          Copy Protected: No

--

          ・

          ・

          ・

 と思ったらこれは失敗だ。

 Typefaces:の行から辿って情報を取得することにしよう。

 

do shell script "system_profiler SPFontsDataType | grep -A2 -e 'Typefaces:' -e 'Enabled:' | grep -B4 -e 'Enabled: Yes' | grep -A4 -e 'Typefaces:' | grep -e ':' | grep -B2 -e 'Enabled:' | grep -v 'Enabled:' | cut -c9- ;"

 

 

TimesNewRomanPS-BoldMT:

  Full Name: Times New Roman Bold

 

WeibeiSC-Bold:

  Full Name: Weibei SC Bold

 

BMYEONSUNG-OTF:

  Full Name: BM YEONSUNG OTF

 

AppleBraille-Pinpoint8Dot:

  Full Name: Apple Braille Pinpoint 8 Dot

 

Georgia-Bold:

  Full Name: Georgia Bold

          ・

          ・

なんとかできたけど、なんかすごく格好の悪いものになってしまった。

同じテキストで辿って、切り捨てて・・・

Enabled: Yesの使用可能フォントの部分だけ抜き出してはいるはず。

 

もっと整理できたらしてみたい。


nice!(0)  コメント(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 0

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。