NSFontManager

[NSFontManager]フォント名の取得(修正)


【スクリプトエディタで開く】 |

[NSFontManager]フォント名の取得.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004
005フォント名PS名の取得
006フォントフルネームの取得 をそれぞれリストで出力
007
008com.cocolog-nifty.quicktimer.icefloe *)
009----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
010use AppleScript version "2.8"
011use framework "Foundation"
012use framework "AppKit"
013use scripting additions
014
015property refMe : a reference to current application
016###################################
017#フォント初期化
018set appFontManager to refMe's NSFontManager
019set appSharedMaanager to appFontManager's sharedFontManager()
020#利用可能なフォントリスト(PS名のリストになる)
021set ocidPsNameArray to appSharedMaanager's availableFonts()
022#格納用のレコード
023set ocidFontNameeDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
024###フォントの数だけ繰り返し
025repeat with itemPsName in ocidPsNameArray
026   #名前でFONTを呼び出して
027   set ocidItemFont to (refMe's NSFont's fontWithName:(itemPsName) |size|:(10))
028   #詳細情報を取得して
029   #   set ocidFontDiscripter to ocidItemFont's fontDescriptor()
030   #postscript
031   #   set ocidPostScriptName to ocidFontDiscripter's postscriptName()
032   #   set ocidFontAttrDict to ocidFontDiscripter's fontAttributes()
033   #postscript
034   #   set ocidPostScriptName to  ocidFontAttrDict's objectForKey:(refMe's NSFontNameAttribute)
035   #   set ocidFamilyName to  (ocidFontAttrDict's objectForKey:(refMe's NSFontFamilyAttribute)) as text
036   #ローカライズされたフォント名フルネーム
037   set ocidDisplayName to ocidItemFont's displayName()
038   #   set ocidFamilyName to ocidItemFont's familyName()
039   #これはPS
040   set ocidFontName to ocidItemFont's fontName()
041   #DICTにセット
042   (ocidFontNameeDict's setValue:(ocidFontName) forKey:(ocidDisplayName))
043end repeat
044
045#フォント名一覧
046set ocidFontNameArray to ocidFontNameeDict's allKeys()
047#ソートして
048set ocidFontNameArray to ocidFontNameArray's sortedArrayUsingSelector:("localizedStandardCompare:")
049#フォント名一覧
050log ocidFontNameArray as list
051#Value用のArray
052set ocidPsNameArrayM to refMe's NSMutableArray's alloc()'s init()
053
054repeat with itemKeys in ocidFontNameArray
055   set ocidValue to (ocidFontNameeDict's valueForKey:(itemKeys))
056   (ocidPsNameArrayM's addObject:(ocidValue))
057end repeat
058#こっちはPS名一覧
059return ocidPsNameArrayM as list
AppleScriptで生成しました

AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004#
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use scripting additions
010
011property refMe : a reference to current application
012###################################
013#フォント初期化
014set appFontManager to refMe's NSFontManager
015set appSharedMaanager to appFontManager's sharedFontManager()
016#利用可能なフォントリスト(PS名のリストになる)
017set ocidPsNameArray to appSharedMaanager's availableFonts()
018#格納用のレコード
019set ocidFontNameeDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
020###フォントの数だけ繰り返し
021repeat with itemPsName in ocidPsNameArray
022  #名前でFONTを呼び出して
023  set ocidItemFont to (refMe's NSFont's fontWithName:(itemPsName) |size|:(10))
024  #詳細情報を取得して
025  # set ocidFontDiscripter to ocidItemFont's fontDescriptor()
026  #postscript名
027  # set ocidPostScriptName to ocidFontDiscripter's postscriptName()
028  # set ocidFontAttrDict to ocidFontDiscripter's fontAttributes()
029  #postscript名
030  # set ocidPostScriptName to  ocidFontAttrDict's objectForKey:(refMe's NSFontNameAttribute)
031  # set ocidFamilyName to  (ocidFontAttrDict's objectForKey:(refMe's NSFontFamilyAttribute)) as text
032  #ローカライズされたフォント名フルネーム
033  set ocidDisplayName to ocidItemFont's displayName()
034  # set ocidFamilyName to ocidItemFont's familyName()
035  #これはPS名
036  set ocidFontName to ocidItemFont's fontName()
037  #DICTにセット
038  (ocidFontNameeDict's setValue:(ocidFontName) forKey:(ocidDisplayName))
039end repeat
AppleScriptで生成しました

|

[NSFont]フォント名の取得(フォント名=FULLNAME 英語 日本語ローカライズ名 postscript名)

ポストスクリプト名
AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005# com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011
012property refMe : a reference to current application
013
014
015###################################
016#フォント初期化
017set appFontManager to refMe's NSFontManager
018set appSharedMaanager to appFontManager's sharedFontManager()
019#利用可能なフォントリスト(PS名のリストになる)
020-->結果これでも良いわけですが
021set ocidPsNameArray to appSharedMaanager's availableFonts()
022#格納用のレコード
023set ocidFontNameeDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
024###フォントの数だけ繰り返し
025repeat with itemPsName in ocidPsNameArray
026  #名前で呼び出して
027  set ocidItemFont to (refMe's NSFont's fontWithName:(itemPsName) matrix:(missing value))
028  #詳細情報を取得して
029  set ocidFontDiscripter to ocidItemFont's fontDescriptor()
030  #postscript名
031  log ocidFontDiscripter's postscriptName() as text
032  
033end repeat
034
035
036
037
038return
AppleScriptで生成しました

フォントのフルネーム ローカライズ(OSの設定言語でのフォント名)
AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005# com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011
012property refMe : a reference to current application
013
014
015###################################
016#フォント初期化
017set appFontManager to refMe's NSFontManager
018set appSharedMaanager to appFontManager's sharedFontManager()
019#利用可能なフォントリスト(PS名のリストになる)
020set ocidPsNameArray to appSharedMaanager's availableFonts()
021#格納用のレコード
022set ocidFontNameeDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
023###フォントの数だけ繰り返し
024repeat with itemPsName in ocidPsNameArray
025  #PS名からNSFontを生成して
026  set ocidItemFont to (refMe's NSFont's fontWithName:(itemPsName) matrix:(missing value))
027  #OSの言語のフォントFULL NAMEの取得
028  set ocidDisplayName to ocidItemFont's displayName()
029  log ocidDisplayName as text
030end repeat
031
032return
033
AppleScriptで生成しました

フォントのフルネーム(英語でのフルネーム)
AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#
004#
005# com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011
012property refMe : a reference to current application
013
014
015###################################
016#フォント初期化
017set appFontManager to refMe's NSFontManager
018set appSharedMaanager to appFontManager's sharedFontManager()
019#利用可能なフォントリスト(PS名のリストになる)
020set ocidPsNameArray to appSharedMaanager's availableFonts()
021#格納用のレコード
022set ocidFontNameeDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
023###フォントの数だけ繰り返し
024repeat with itemPsName in ocidPsNameArray
025  #PS名からNSFontを生成して
026  set ocidItemFont to (refMe's NSFont's fontWithName:(itemPsName) matrix:(missing value))
027  #Descriptorを取得
028  set ocidFontDiscripter to ocidItemFont's fontDescriptor()
029  #NSFontVisibleNameAttributeが英語のフォント名
030  set ocidFontFullName to (ocidFontDiscripter's objectForKey:(refMe's NSFontVisibleNameAttribute))
031  log ocidFontFullName as text
032end repeat
033
034return
035
AppleScriptで生成しました

|

Fontのpostscript名を取得する(訂正)


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#  
004#
005# com.cocolog-nifty.quicktimer.icefloe
006----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
007use AppleScript version "2.8"
008use framework "Foundation"
009use framework "AppKit"
010use scripting additions
011property refMe : a reference to current application
012
013
014###################################
015##### フォント収集
016###################################
017###フォント初期化
018set appFontManager to (refMe's NSFontManager)
019set appSharedMaanager to appFontManager's sharedFontManager()
020###利用可能なフォントリスト
021set ocidFontList to appSharedMaanager's availableFonts()
022###格納用のレコード
023set ocidFontNameeDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
024
025###フォントの数だけ繰り返し
026repeat with itemFontList in ocidFontList
027  ###PS名でフォントオブジェクトにして
028  set ocidTempFont to (refMe's NSFont's fontWithName:(itemFontList) matrix:(missing value))
029  ###収録文字数を調べ
030  set intCharCnt to ocidTempFont's numberOfGlyphs as integer
031  ###5000文字以上なら日本語もあるだろって事で
032  if intCharCnt > 5000 then
033    set strDisplayName to ocidTempFont's displayName as text
034    ###レコードに追加キー名を表示名で 値はPS名
035    (ocidFontNameeDict's setObject:(itemFontList) forKey:(strDisplayName))
036  end if
037end repeat
038
039
040###################################
041##### ダイアログ
042###################################
043###ダイアログを前面に
044tell current application
045  set strName to name as text
046end tell
047####スクリプトメニューから実行したら
048if strName is "osascript" then
049  tell application "Finder"
050    activate
051  end tell
052else
053  tell current application
054    activate
055  end tell
056end if
057
058###格納用の可変リスト
059set ocidFontNameeArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
060###ディレクトリのallKeysで値のみのリスト=表示名のリスト
061ocidFontNameeArray's addObjectsFromArray:(ocidFontNameeDict's allKeys())
062###並び替え
063set ocidSortDescriptor to (refMe's NSSortDescriptor's sortDescriptorWithKey:("self") ascending:(true) selector:"localizedStandardCompare:")
064(ocidFontNameeArray's sortUsingDescriptors:{ocidSortDescriptor})
065####デフォルト選択値
066set strDefailtsFont to "Osaka−等幅" as text
067##JSOC番号なので0スタート値なので1足す
068set intDefaultsFont to (ocidFontNameeArray's indexOfObject:(strDefailtsFont)) + 1 as integer
069###ASリストにする
070set listFontList to ocidFontNameeArray as list
071###ダイアログ
072try
073  set listResponse to (choose from list listFontList with title "選んでください" with prompt "フォントを選んでください" default items (item intDefaultsFont of listFontList) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
074on error
075  log "エラーしました"
076  return "エラーしました"
077end try
078if (item 1 of listResponse) is false then
079  return "キャンセルしました"
080end if
081#
082set strFontName to (item 1 of listResponse)
083
084
085#この記述でも戻り値はpostscriptNameですが
086log (ocidFontNameeDict's valueForKey:(strFontName)) as text
087####
088#正しくはこの方法
089set ocidChooseFont to refMe's NSFont's fontWithName:(strFontName) |size|:(72)
090set ocidFontDiscriptor to ocidChooseFont's fontDescriptor()
091set strPostScriptName to ocidFontDiscriptor's postscriptName() as text
092#フォントのPostScript名称
093log strPostScriptName
094
AppleScriptで生成しました

|

[NSFontManager]フォントのリストを取得する(基本編)


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004# 日本語判定方法がわからないので現状はここまで
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use scripting additions
010
011property refMe : a reference to current application
012
013set appFontManager to (refMe's NSFontManager's sharedFontManager())
014#フォント
015set ocidFontArray to appFontManager's availableFonts()
016set numCntFont to ocidFontArray's |count|()
017log "フォント数:" & numCntFont
018#フォントファミリー
019set ocidFontFamiliesArray to appFontManager's availableFontFamilies()
020set numCntFontFamily to ocidFontFamiliesArray's |count|()
021log "フォントファミリー数:" & numCntFontFamily
022
023#ファミリー順に繰り返し
024repeat with itemFontFamily in ocidFontFamiliesArray
025  log "フォントファミリー名:" & itemFontFamily
026  set ocidFontArray to (appFontManager's availableMembersOfFontFamily:(itemFontFamily))
027  repeat with itemFont in ocidFontArray
028    log "POST SCRIPT NAME名:" & (itemFont's objectAtIndex:(0))
029    log "SUB NAME スタイル名:" & (itemFont's objectAtIndex:(1))
030    log "フォントのウェイト 細1<-->太12:" & (itemFont's objectAtIndex:(2))
031    log "フォントの種類:" & (itemFont's objectAtIndex:(3))
032    (*
033log refMe's NSBoldFontMask as integer
034-->(*2*)
035log refMe's NSCompressedFontMask as integer
036-->(*512*)
037log refMe's NSCondensedFontMask as integer
038-->(*64*)
039log refMe's NSExpandedFontMask as integer
040-->(*32*)
041log refMe's NSFixedPitchFontMask as integer
042-->(*1024*)
043log refMe's NSItalicFontMask as integer
044-->(*1*)
045log refMe's NSNarrowFontMask as integer
046-->(*16*)
047log refMe's NSNonStandardCharacterSetFontMask as integer
048-->(*8*)
049log refMe's NSPosterFontMask as integer
050-->(*256*)
051log refMe's NSSmallCapsFontMask as integer
052-->(*128*)
053log refMe's NSUnboldFontMask as integer
054-->(*4*)
055log refMe's NSUnitalicFontMask as integer
056-->(*16777216*)
057*)
058  end repeat
059end repeat
AppleScriptで生成しました


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#! /usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004# 日本語判定方法がわからないので現状はここまで
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006use AppleScript version "2.8"
007use framework "Foundation"
008use framework "AppKit"
009use scripting additions
010
011property refMe : a reference to current application
012
013set appFontManager to (refMe's NSFontManager's sharedFontManager())
014
015set listFontMask to {(refMe's NSBoldFontMask), (refMe's NSCompressedFontMask), (refMe's NSCondensedFontMask), (refMe's NSExpandedFontMask), (refMe's NSFixedPitchFontMask), (refMe's NSItalicFontMask), (refMe's NSNarrowFontMask), (refMe's NSNonStandardCharacterSetFontMask), (refMe's NSPosterFontMask), (refMe's NSSmallCapsFontMask), (refMe's NSUnboldFontMask), (refMe's NSUnitalicFontMask)}
016repeat with itemMask in listFontMask
017  set ocidFontTraitsArray to (appFontManager's availableFontNamesWithTraits:(itemMask))
018  log ocidFontTraitsArray as list
019end repeat
AppleScriptで生成しました

|

[font book]フォントライブラリを作成する

ローカルドメイン(system liblary application)はURL形式のパス
ユーザードメイン(ホームディレクトリ)はエイリアスデータbookmarkのNSdataの登録となり
処理が異なる。

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application

###フォントブックを終了
tell application id "com.apple.FontBook"
  quit
end tell

##############################
###ライブラリ名を指定 ダイアログ
set appFileManager to refMe's NSFileManager's defaultManager()
###FontCollectionsのフォルダパス
set ocidUserLibraryPathArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserLibraryPath to ocidUserLibraryPathArray's firstObject()
set ocidFontCollectionsURL to ocidUserLibraryPath's URLByAppendingPathComponent:("FontCollections") isDirectory:(true)
set aliasFontCollectionsURL to ocidFontCollectionsURL's absoluteURL() as alias
##############################
#####ダイアログを前面に
tell current application
  set strName to name as text
end tell
####スクリプトメニューから実行したら
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
##############################
###ダイアログ
set strDefaultName to "名称未設定.library" as text
set strExtension to "library"
set strPromptText to "フォントライブラリの名前を決めてください" as text
set strMesText to "フォントライブラリの名前を決めてください" as text
set aliasFilePath to (choose file name strMesText default location aliasFontCollectionsURL default name strDefaultName with prompt strPromptText) as «class furl»
##############################
###ライブラリファイルのパス
set strFilePath to (POSIX path of aliasFilePath) as text
set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath)
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false)
set ocidFileName to ocidFilePathURL's lastPathComponent()
set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension()
set ocidExtensionName to ocidFilePathURL's pathExtension()
###空の文字列 if文用
set ocidEmptyString to refMe's NSString's alloc()'s init()
if ocidExtensionName = ocidEmptyString then
  ###ダイアログで拡張子取っちゃった場合対策
  set ocidFilePathURL to ocidFilePathURL's URLByAppendingPathExtension:(strExtension)
end if

##############################
### フォルダ選択 
###(選択したフォルダの最下層までフォントを取得する)
set ocidUserDesktopPathArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidUserDesktopPath to ocidUserDesktopPathArray's firstObject()
###ダイアログ
set aliasFontCollectionsURL to ocidUserDesktopPath's absoluteURL() as alias
set strMes to "フォルダを選んでください"
set strPrompt to "フォントをライブラリに登録するフォルダ(フォントが入っているフォルダ)を選んでください"
set aliasFolderPath to (choose folder strMes with prompt strPrompt default location aliasFontCollectionsURL with invisibles and showing package contents without multiple selections allowed)
##############################
###読み込むフォントのパス
set strFontsDirPath to POSIX path of aliasFolderPath as text
set ocidFontsDirPathStr to refMe's NSString's stringWithString:(strFontsDirPath)
set ocidFontsDirPath to ocidFontsDirPathStr's stringByStandardizingPath()
set ocidFontsDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFontsDirPath) isDirectory:true)
##############################
##### ユーザー ドメイン専用
if strFontsDirPath starts with "/Users" then
  log "処理開始"
  ###########################################
  ###ユーザーフォント用
  ###########################################
  ##############################
  ###enumeratorAtURLL格納するリスト
  set ocidEmuFileURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  ###フォントファイルのURLのみを格納するリスト
  set ocidFontFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  
  ##############################
  ###ディレクトリのコンテツを収集
  ###収集する付随プロパティ
  set ocidPropertiesForKeys to {(refMe's NSURLContentTypeKey), (refMe's NSURLIsRegularFileKey)}
  ####ディレクトリのコンテツを収集
  set ocidEmuDict to (appFileManager's enumeratorAtURL:(ocidFontsDirPathURL) includingPropertiesForKeys:ocidPropertiesForKeys options:(refMe's NSDirectoryEnumerationSkipsHiddenFiles) errorHandler:(reference))
  ###戻り値用のリストに格納
ocidEmuFileURLArray's addObjectsFromArray:(ocidEmuDict's allObjects)
  
  ##############################
  ###『ファイル』だけ取り出したリストにする
  ####enumeratorAtURLのかずだけ繰り返し
  repeat with itemEmuFileURL in ocidEmuFileURLArray
    ####URLをforKeyで取り出し
    set listResult to (itemEmuFileURL's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error|:(reference))
    ###リストからNSURLIsRegularFileKeyのBOOLを取り出し
    set boolIsRegularFileKey to item 2 of listResult
    log boolIsRegularFileKey as text
    ####ファイルのみを(ディレクトリやリンボリックリンクは含まない)
    if boolIsRegularFileKey is (refMe's NSNumber's numberWithBool:true) then
      set listResult to (itemEmuFileURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
      set ocidContentType to item 2 of listResult
      set strUTI to (ocidContentType's identifier) as text
      if strUTI contains "font" then
####リストにする
(ocidFontFilePathURLArray's addObject:(itemEmuFileURL))
      end if
    end if
  end repeat
  
  ##############################
  ###URL格納用(absoluteString)
  set ocidFontPathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  repeat with itemAliasFontPath in ocidFontFilePathURLArray
(ocidFontPathArray's addObject:(itemAliasFontPath))
  end repeat
  
  ##############################
  ###PLISTのデータになるDict
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  ###bookmarks
  set ocidBookmarks to refMe's NSMutableDictionary's alloc()'s init()
  ##############################
  ###containerURLs
  set ocidContainerURLs to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  repeat with itemFontPathArray in ocidFontPathArray
    ###このifは不要かな?
    set ocidFontStrigsPath to (itemFontPathArray's |path|())
    if (ocidFontStrigsPath as text) starts with "/Users/" then
      ###containerURLsはパスとエイリアスデータ
      set strRelativePath to "/" as text
      set ocidRelativePathStr to (refMe's NSString's stringWithString:(strRelativePath))
      set ocidRelativePath to ocidRelativePathStr's stringByStandardizingPath()
      set ocidRelativeToURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidRelativePath) isDirectory:true)
      set ocidBookMarkPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFontStrigsPath) isDirectory:false)
      ##############################
      ###bookmark エイリアスデータ生成
      set ocidBookMarkDataArray to (ocidBookMarkPathURL's bookmarkDataWithOptions:(11) includingResourceValuesForKeys:({missing value}) relativeToURL:(missing value) |error|:(reference))
      set ocidBookMarkData to item 1 of ocidBookMarkDataArray
      ###bookmarkデータを追加
(ocidBookmarks's setObject:(ocidBookMarkData) forKey:(ocidFontStrigsPath))
    else
      set strAbsoluteStringPath to (itemFontPathArray's absoluteString())
(ocidContainerURLs's addObject:(strAbsoluteStringPath))
    end if
  end repeat
ocidPlistDict's setObject:(ocidBookmarks) forKey:("bookmarks")
ocidPlistDict's setObject:(ocidContainerURLs) forKey:("containerURLs")
  ###disabled
  set ocidFalse to (refMe's NSNumber's numberWithBool:false)
ocidPlistDict's setValue:(ocidFalse) forKey:("disabled")
  ###name
ocidPlistDict's setValue:(ocidBaseFileName) forKey:("name")
  ###reference
  set ocidReference to refMe's NSNumber's numberWithInteger:(1)
ocidPlistDict's setValue:(ocidReference) forKey:("reference")
  ###date
  set ocidDate to (refMe's NSDate's |date|())
  set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setDateFormat:("yyyy-MM-dd'T'HH:mm:ss'Z'")
ocidFormatter's setTimeZone:(refMe's NSTimeZone's timeZoneWithAbbreviation:("UTC"))
  set ocidSetDate to ocidFormatter's stringFromDate:(ocidDate)
  -->string形式でセットするのでsetValueで
ocidPlistDict's setValue:(ocidSetDate) forKey:("date")
  ##############################
  ###urlAddedDates
  set ocidUrlAddedDates to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  ###フォントのURLを追加(absoluteString形式)
  repeat with itemFontPathArray in ocidFontPathArray
    set strPath to (itemFontPathArray's |path|())
(ocidUrlAddedDates's setValue:(ocidSetDate) forKey:(strPath))
  end repeat
ocidPlistDict's setObject:(ocidUrlAddedDates) forKey:("urlAddedDates")
  ###version
ocidFormatter's setDateFormat:("yyyyMMdd")
  set ocidversion to ocidFormatter's stringFromDate:(ocidDate)
ocidPlistDict's setValue:(ocidversion) forKey:("version")
  ######################
  ###XML形式
  set ocidXmlplist to refMe's NSPropertyListXMLFormat_v1_0
  ####書き込み用にXMLに変換
  set ocidPlistEditData to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidXmlplist) options:0 |error|:(missing value)
  ####書き込み
ocidPlistEditData's writeToURL:(ocidFilePathURL) atomically:true
else
  ###########################################
  ###ローカルフォント用
  ###########################################
  ###enumeratorAtURLL格納するリスト
  set ocidEmuFileURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  ###フォントファイルのURLのみを格納するリスト
  set ocidFontFilePathURLArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  
  ##############################
  #####ディレクトリのコンテツを収集
  ###収集する付随プロパティ
  set ocidPropertiesForKeys to {(refMe's NSURLContentTypeKey), (refMe's NSURLIsRegularFileKey)}
  ####ディレクトリのコンテツを収集
  set ocidEmuDict to (appFileManager's enumeratorAtURL:(ocidFontsDirPathURL) includingPropertiesForKeys:ocidPropertiesForKeys options:(refMe's NSDirectoryEnumerationSkipsHiddenFiles) errorHandler:(reference))
  ###戻り値用のリストに格納
ocidEmuFileURLArray's addObjectsFromArray:(ocidEmuDict's allObjects)
  
  ##############################
  #####『ファイル』だけ取り出したリストにする
  ####enumeratorAtURLのかずだけ繰り返し
  repeat with itemEmuFileURL in ocidEmuFileURLArray
    
    ####URLをforKeyで取り出し
    set listResult to (itemEmuFileURL's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error|:(reference))
    ###リストからNSURLIsRegularFileKeyのBOOLを取り出し
    set boolIsRegularFileKey to item 2 of listResult
    log boolIsRegularFileKey as text
    ####ファイルのみを(ディレクトリやリンボリックリンクは含まない)
    if boolIsRegularFileKey is (refMe's NSNumber's numberWithBool:true) then
      set listResult to (itemEmuFileURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference))
      set ocidContentType to item 2 of listResult
      set strUTI to (ocidContentType's identifier) as text
      if strUTI contains "font" then
####リストにする
(ocidFontFilePathURLArray's addObject:(itemEmuFileURL))
      end if
    end if
  end repeat
  
  ##############################
  #####URL格納用(absoluteString)
  set ocidFontPathArray to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  repeat with itemAliasFontPath in ocidFontFilePathURLArray
(ocidFontPathArray's addObject:(itemAliasFontPath))
  end repeat
  
  ##############################
  ##### PLIST処理
  ###PLISTのデータになるDict
  set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  ###bookmarks
  set ocidBookmarks to refMe's NSMutableDictionary's alloc()'s init()
ocidPlistDict's setObject:(ocidBookmarks) forKey:("bookmarks")
  #####################
  ###containerURLs
  set ocidContainerURLs to refMe's NSMutableArray's alloc()'s initWithCapacity:0
  ###フォントのURLを追加(absoluteString形式)
  repeat with itemFontPathArray in ocidFontPathArray
    set strAbsoluteStringPath to (itemFontPathArray's absoluteString())
(ocidContainerURLs's addObject:(strAbsoluteStringPath))
  end repeat
ocidPlistDict's setObject:(ocidContainerURLs) forKey:("containerURLs")
  ###disabled
  set ocidFalse to (refMe's NSNumber's numberWithBool:false)
ocidPlistDict's setValue:(ocidFalse) forKey:("disabled")
  ###name
ocidPlistDict's setValue:(ocidBaseFileName) forKey:("name")
  ###reference
  set ocidReference to refMe's NSNumber's numberWithInteger:(1)
ocidPlistDict's setValue:(ocidReference) forKey:("reference")
  ###date
  set ocidDate to (refMe's NSDate's |date|())
  set ocidFormatter to refMe's NSDateFormatter's alloc()'s init()
ocidFormatter's setDateFormat:("yyyy-MM-dd'T'HH:mm:ss'Z'")
ocidFormatter's setTimeZone:(refMe's NSTimeZone's timeZoneWithAbbreviation:("UTC"))
  set ocidSetDate to ocidFormatter's stringFromDate:(ocidDate)
  -->string形式でセットするのでsetValueで
ocidPlistDict's setValue:(ocidSetDate) forKey:("date")
  #####################
  ###urlAddedDates
  set ocidUrlAddedDates to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
  ###フォントのURLを追加(absoluteString形式)
  repeat with itemFontPathArray in ocidFontPathArray
    set strPath to (itemFontPathArray's |path|())
(ocidUrlAddedDates's setValue:(ocidSetDate) forKey:(strPath))
  end repeat
ocidPlistDict's setObject:(ocidUrlAddedDates) forKey:("urlAddedDates")
  ###version
ocidFormatter's setDateFormat:("yyyyMMdd")
  set ocidversion to ocidFormatter's stringFromDate:(ocidDate)
ocidPlistDict's setValue:(ocidversion) forKey:("version")
  
  ######################
  ###XML形式
  set ocidXmlplist to refMe's NSPropertyListXMLFormat_v1_0
  ####書き込み用にXMLに変換
  set ocidPlistEditData to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidXmlplist) options:0 |error|:(missing value)
  ####書き込み
ocidPlistEditData's writeToURL:(ocidFilePathURL) atomically:true
  
end if


###フォントブックを起動
tell application id "com.apple.FontBook"
  launch
end tell



|

フォント名を選ぶ


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application
##デフォルト
set strDefailtsFont to "Osaka-Mono" as text
set appFontManager to refMe's NSFontManager
set appSharedMaanager to appFontManager's sharedFontManager()
set ocidFontListArray to appSharedMaanager's availableFonts()
set numDefaultsFont to (ocidFontListArray's indexOfObject:(strDefailtsFont)) as integer
set listFontList to ocidFontListArray as list
try
  set listResponse to (choose from list listFontList with title "選んでください" with prompt "フォントを選んでください" default items (item numDefaultsFont of listFontList) OK button name "OK" cancel button name "キャンセル" without multiple selections allowed and empty selection allowed) as list
on error
  log "エラーしました"
return "エラーしました"
end try
if listResponse is false then
return "キャンセルしました"
end if

set strFontName to (item 1 of listResponse)

|

ファイルサイズ

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
#                       com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions

property refMe : a reference to current application


set appFileManager to refMe's NSFileManager's defaultManager()

set strFilePath to "/Library/Documentation/Acknowledgements.rtf"
#####NSString
set ocidFilePathStr to refMe's NSString's stringWithString:strFilePath
#####NSPathStore2
set ocidFilePath to ocidFilePathStr's stringByStandardizingPath
###### attributesを取得
set ocidAttributes to appFileManager's attributesOfItemAtPath:ocidFilePath |error|:(missing value)
#####ファイルサイズを取得
set ocidNSFileSize to ocidAttributes's NSFileSize
set numFileSize to ocidNSFileSize as integer
log numFileSize
#####KB
set numKB to (refMe's NSNumber's numberWithFloat:(numFileSize / 1024))
log numKB as text
log (numFileSize / 1024)
log ((round ((numFileSize / 1024) * 10)) / 10) as text
#####MB
set numKB to (refMe's NSNumber's numberWithFloat:((numFileSize / 1024) / 1024))
log numKB as text
log ((numFileSize / 1024) / 1024)
log ((round ((numFileSize / 1024) * 100)) / 100) as text

|

[NSFontManager]フォントリスト あれこれ

フォント名

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application



set appFontManager to refMe's NSFontManager
set appSharedMaanager to appFontManager's sharedFontManager()
set ocidFontList to appSharedMaanager's availableFonts()

repeat with itemFontList in ocidFontList
  
  log itemFontList as text
  
end repeat



フォントファミリー

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application



set appFontManager to refMe's NSFontManager
set appSharedMaanager to appFontManager's sharedFontManager()
set ocidFontList to appSharedMaanager's availableFontFamilies()

repeat with itemFontList in ocidFontList
  
  log itemFontList as text
  
end repeat



スタイル別で指定(NSFontTraitMask)

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application



set appFontManager to refMe's NSFontManager
set appSharedMaanager to appFontManager's sharedFontManager()
set ocidFontList to appSharedMaanager's availableFontNamesWithTraits:(refMe's NSBoldFontMask)
(*
NSBoldFontMask
NSCompressedFontMask
NSCondensedFontMask
NSExpandedFontMask
NSFixedPitchFontMask
NSItalicFontMask
NSNarrowFontMask
NSNonStandardCharacterSetFontMask
NSPosterFontMask
NSSmallCapsFontMask
NSUnboldFontMask
NSUnitalicFontMask
*)

repeat with itemFontList in ocidFontList
  
  log itemFontList as text
  
end repeat



フォントファミリーメンバー

【スクリプトエディタで開く】

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.6"
use framework "foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application



set appFontManager to refMe's NSFontManager
set appSharedMaanager to appFontManager's sharedFontManager()
set ocidFontList to appSharedMaanager's availableFontFamilies()

repeat with itemFontList in ocidFontList
  set ocidFamilyMember to (appSharedMaanager's availableMembersOfFontFamily:itemFontList)
  
  repeat with itemFamilyMember in ocidFamilyMember
    log itemFamilyMember as list
    
  end repeat
  
end repeat

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat 2024 Acrobat AddOn Acrobat Annotation Acrobat AppleScript Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat GentechAI Acrobat JS Acrobat JS Word Search Acrobat Maintenance Acrobat Manifest Acrobat Menu Acrobat Merge Acrobat Open Acrobat PDFPage Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat Print Acrobat Python Acrobat Reader Acrobat Reader Localized Acrobat Reference Acrobat Registered Products Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat URL List Mac Acrobat URL List Windows Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin ConfigCode Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin NetWork Admin Permission Admin Pkg Admin Power Management Admin Printer Admin Printer Basic Admin Printer Custompapers Admin SetUp Admin SMB Admin softwareupdate Admin Support Admin System Information Admin TCC Admin Tools Admin Umask Admin Users Admin Volumes Admin XProtect Adobe Adobe AUSST Adobe Bridge Adobe Documents Adobe FDKO Adobe Fonts Adobe Reference Adobe RemoteUpdateManager Adobe Sap Code AppKit Apple AppleScript AppleScript Duplicate AppleScript entire contents AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Video Applications AppStore Archive Archive Keka Attributes Automator BackUp Barcode Barcode Decode Barcode QR Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome Chromedriver CIImage CityCode CloudStorage Color Color NSColor Color NSColorList com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Desktop Position Device Diff Disk do shell script Dock Dock Launchpad DropBox Droplet eMail Encode % Encode Decode Encode HTML Entity Encode UTF8 Error EXIFData exiftool ffmpeg File File Name Finder Finder Window Firefox Folder FolderAction Font List FontCollections Fonts Fonts Asset_Font Fonts ATS Fonts Emoji Fonts Maintenance Fonts Morisawa Fonts Python Fonts Variable Foxit GIF github Guide HTML Icon Icon Assets.car Illustrator Image Events ImageOptim Input Dictionary iPhone iWork Javascript Jedit Ω Json Label Language Link locationd lsappinfo m3u8 Mail Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Microsoft Fonts Microsoft Office Microsoft Office Link Microsoft OneDrive Microsoft Teams Mouse Music Node Notes NSArray NSArray Sort NSAttributedString NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSGraphicsContext Crop NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMetadataItem NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSet NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSUbiquitous NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth PDF PDF Image2PDF PDF MakePDF PDF nUP PDF Pymupdf PDF Pypdf PDFContext PDFDisplayBox PDFImageRep PDFKit PDFKit Annotation PDFKit AnnotationWidget PDFKit DocumentPermissions PDFKit OCR PDFKit Outline PDFKit Start PDFPage PDFPage Rotation PDFView perl Photoshop PlistBuddy pluginkit plutil postalcode PostScript PowerShell prefPane Preview Python Python eyed3 Python pip QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver Script Editor Script Menu SF Symbols character id SF Symbols Entity Shortcuts Shortcuts Events sips Skype Slack Sound Spotlight sqlite StandardAdditions StationSearch Subtitles LRC Subtitles SRT Subtitles VTT Swift swiftDialog System Events System Settings TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code VMware Fusion Wacom Weather webarchive webp Wifi Windows XML XML EPUB XML HTML XML LSSharedFileList XML LSSharedFileList sfl2 XML LSSharedFileList sfl3 XML objectsForXQuery XML OPML XML Plist XML Plist System Events XML RSS XML savedSearch XML SVG XML TTML XML webloc XML xmllint XML XMP YouTube Zero Padding zoom