使用中のmacOS環境にインストールされているフォントのmostCompatibleStringEncodingを求めて、集計出力するAppleScriptです。
mostCompatibleStringEncodingはフォントが対応しているエンコーディングということで、普通そんなものはないように思えますが、EnglishなどのAscii & Numelicだけの言語用フォントであれば、「それにしか対応していない」という意味でのmostCompatibleStringEncodingはあるんじゃないかと。
一応調査するために書いてみたものです。バーコード系のフォントやドットフォントが該当しそうな感じです。
AppleScript名:全フォントのmostCompatibleStringEncodingを求める.scptd |
— – Created by: Takaaki Naganoya – Created on: 2024/11/06 — – Copyright © 2024 Piyomaru Software, All Rights Reserved — use AppleScript use scripting additions use framework "Foundation" property NSFont : a reference to current application’s NSFont property NSPredicate : a reference to current application’s NSPredicate property NSFontManager : a reference to current application’s NSFontManager script spdf property fList : {} property outList : {} end script set (outList of spdf) to {} set (fList of spdf) to getEveryFontPSName() of me repeat with i in (fList of spdf) set j to contents of i set aEnc to chkFontsCompatibleEncoding(j) of me –if aEnc is not equal to "default" then set the end of (outList of spdf) to {fontEncoding:aEnc} set the end of (outList of spdf) to {fontEncoding:aEnc} end repeat set aCountedList to countEachRecord((outList of spdf)) of me –> {{aCount:1, aData:{fontEncoding:"NSSymbolStringEncoding"}}, {aCount:860, aData:{fontEncoding:"default"}}, {aCount:1005, aData:{fontEncoding:"NSMacOSRomanStringEncoding"}}} –Rec in Listの登場頻度を集計して出力 on countEachRecord(aRecList) set theCountedSet to current application’s NSCountedSet’s |set|() repeat with i in aRecList set j to contents of i (theCountedSet’s addObject:j) end repeat set theEnumerator to theCountedSet’s objectEnumerator() set anArray to current application’s NSMutableArray’s alloc()’s init() repeat set aDict to current application’s NSMutableDictionary’s alloc()’s init() set aValue to theEnumerator’s nextObject() if aValue is missing value then exit repeat set aCount to theCountedSet’s countForObject:aValue aDict’s setObject:aCount forKey:"aCount" aDict’s setObject:aValue forKey:"aData" anArray’s addObject:aDict end repeat return anArray as anything end countEachRecord on getEveryFontPSName() script spd property aList : {} end script set aFontList to NSFontManager’s sharedFontManager()’s availableFonts() set thePred to NSPredicate’s predicateWithFormat:"NOT SELF BEGINSWITH ’.’" set aFontList to (aFontList’s filteredArrayUsingPredicate:thePred) as list set aList of spd to {} repeat with i in aFontList set aName to contents of i set the end of aList of spd to aName end repeat return aList of spd end getEveryFontPSName on chkFontsCompatibleEncoding(fontPSName as string) set aFont to current application’s NSFont’s fontWithName:(fontPSName) |size|:16 if aFont’s mostCompatibleStringEncoding() = (current application’s NSASCIIStringEncoding) then return "NSASCIIStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSNEXTSTEPStringEncoding) then return "NSNEXTSTEPStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSJapaneseEUCStringEncoding) then return "NSJapaneseEUCStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUTF8StringEncoding) then return "NSUTF8StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSISOLatin1StringEncoding) then return "NSISOLatin1StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSSymbolStringEncoding) then return "NSSymbolStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSNonLossyASCIIStringEncoding) then return "NSNonLossyASCIIStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSShiftJISStringEncoding) then return "NSShiftJISStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSISOLatin2StringEncoding) then return "NSISOLatin2StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUnicodeStringEncoding) then return "NSUnicodeStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSWindowsCP1251StringEncoding) then return "NSWindowsCP1251StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSWindowsCP1252StringEncoding) then return "NSWindowsCP1252StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSWindowsCP1253StringEncoding) then return "NSWindowsCP1253StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSWindowsCP1254StringEncoding) then return "NSWindowsCP1254StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSWindowsCP1250StringEncoding) then return "NSWindowsCP1250StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSISO2022JPStringEncoding) then return "NSISO2022JPStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSMacOSRomanStringEncoding) then return "NSMacOSRomanStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSProprietaryStringEncoding) then return "NSProprietaryStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSISO2022JPStringEncoding) then return "NSISO2022JPStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSJapaneseEUCStringEncoding) then return "NSJapaneseEUCStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSShiftJISStringEncoding) then return "NSShiftJISStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUTF16BigEndianStringEncoding) then return "NSUTF16BigEndianStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUTF16LittleEndianStringEncoding) then return "NSUTF16LittleEndianStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUTF16StringEncoding) then return "NSUTF16StringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUnicodeStringEncoding) then return "NSUnicodeStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUTF32BigEndianStringEncoding) then return "NSUTF32BigEndianStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUTF32LittleEndianStringEncoding) then return "NSUTF32LittleEndianStringEncoding" else if aFont’s mostCompatibleStringEncoding() = (current application’s NSUTF32StringEncoding) then return "NSUTF32StringEncoding" else return "default" end if end chkFontsCompatibleEncoding |