| 001 | #!/usr/bin/env osascript |
| 002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 003 | (* |
| 004 | FontServices.framework(UI等でOSが使うフォント)の中で |
| 005 | 普通にフォントとして機能しそうなフォントだけ |
| 006 | ライブラリを作って登録します |
| 007 |
|
| 008 |
|
| 009 | v1 初回作成 |
| 010 | v1.1 macOS26.4のフォントで再調査 |
| 011 |
|
| 012 |
|
| 013 | com.cocolog-nifty.quicktimer.icefloe *) |
| 014 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 015 | use AppleScript version "2.8" |
| 016 | use framework "Foundation" |
| 017 | use framework "UniformTypeIdentifiers" |
| 018 | use framework "AppKit" |
| 019 | use scripting additions |
| 020 |
|
| 021 | property refMe : a reference to current application |
| 022 |
|
| 023 | ############################## |
| 024 | #フォントブックを終了 |
| 025 | set strBundleID to ("com.apple.FontBook") as text |
| 026 | try |
| 027 | tell application id strBundleID to quit |
| 028 | on error strErrMsg number numErrNo |
| 029 | set strBundleID to (strBundleID) as text |
| 030 | set appRunningAppArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID) |
| 031 | repeat with itemRunApp in appRunningAppArray |
| 032 | set boolDone to itemRunApp's terminate() |
| 033 | if boolDone is false then |
| 034 | set boolDone to itemRunApp's forceTerminate() |
| 035 | end if |
| 036 | end repeat |
| 037 | delay 1 |
| 038 | end try |
| 039 | ############################## |
| 040 | set listFontFilePath to {"/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/AsphaltMedium.otf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/BalegaRegular.otf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/BebasNeue.otf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/FaktSlabStencilPro-medium.otf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/JournalSansInline.otf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/SchemeBold.otf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/TheHandSerif-semibold.otf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Blackmoor LET Fonts.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Blair Medium.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Bodoni SvtyTwo SC Book.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Bordeaux Roman Bold LET Fonts.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Braganza.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Capitals.ttf", "/System/Library/PrivateFrameworks/Slideshows.framework/Versions/A/Resources/Content/Fonts/Coolvetica.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Hopper Script.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Jazz LET Fonts.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Mona Lisa Solid ITC TT.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/PortagoITC TT.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Princetown LET Fonts.ttf", "/System/Library/PrivateFrameworks/Slideshows.framework/Versions/A/Resources/Content/Fonts/Proxima Nova Bold.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Santa Fe LET Fonts.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/SchoolHouse Cursive B.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/SchoolHouse Printed A.ttf", "/System/Library/PrivateFrameworks/PassKitUIFoundation.framework/Versions/A/Resources/SourceSans3-Italic.ttf", "/System/Library/PrivateFrameworks/CoreRecognition.framework/Versions/A/Resources/Fonts/Spendcardium.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Synchro LET Fonts.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Type Embellishments One LET.ttf", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/BankGothic.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Bodoni SvtyTwo OS.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Bodoni SvtyTwo.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/BookAntiqua.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/BookmanOldStyle.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Carlito.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/CenturyGothic.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/CenturySchoolbook.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/DearJoe.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Druk.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/ForgottenFuturist.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Garamond.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/Stone Sans.ttc", "/System/Library/PrivateFrameworks/FontServices.framework/Versions/A/Resources/Fonts/ApplicationSupport/TwentiethCentury.ttc"} as list |
| 041 |
|
| 042 | set ocidFontsPathArray to refMe's NSMutableArray's alloc()'s init() |
| 043 | # |
| 044 | set ocidWhiteUTI to refMe's UTType's typeWithIdentifier:("public.font") |
| 045 | set ocidWhiteSupUTI to ocidWhiteUTI's supertypes() |
| 046 |
|
| 047 | repeat with itemFontFilePath in listFontFilePath |
| 048 | set strFilePath to itemFontFilePath |
| 049 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 050 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 051 | set ocidFilePathURL to (refMe's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 052 | (ocidFontsPathArray's addObject:(ocidFilePathURL)) |
| 053 | end repeat |
| 054 |
|
| 055 |
|
| 056 |
|
| 057 | ############################## |
| 058 | #FontCollectionsのフォルダパス |
| 059 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 060 | set ocidUserLibraryPathArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 061 | set ocidUserLibraryPath to ocidUserLibraryPathArray's firstObject() |
| 062 | set ocidSaveFilePathURL to ocidUserLibraryPath's URLByAppendingPathComponent:("FontCollections/FontServices.library") isDirectory:(false) |
| 063 | set ocidFileName to ocidSaveFilePathURL's lastPathComponent() |
| 064 | set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension() |
| 065 |
|
| 066 | ############################## |
| 067 | # PLIST処理 |
| 068 | #PLISTのデータになるDict |
| 069 | set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s init() |
| 070 |
|
| 071 | #disabled |
| 072 | set ocidFalse to (refMe's NSNumber's numberWithBool:false) |
| 073 | ocidPlistDict's setValue:(ocidFalse) forKey:("disabled") |
| 074 | #name |
| 075 | ocidPlistDict's setValue:(ocidBaseFileName) forKey:("name") |
| 076 | #reference |
| 077 | set ocidReference to refMe's NSNumber's numberWithInteger:(1) |
| 078 | ocidPlistDict's setValue:(ocidReference) forKey:("reference") |
| 079 | #date |
| 080 | set ocidDate to (refMe's NSDate's |date|()) |
| 081 | set ocidFormatter to refMe's NSDateFormatter's alloc()'s init() |
| 082 | ocidFormatter's setDateFormat:("yyyy-MM-dd'T'HH:mm:ss'Z'") |
| 083 | ocidFormatter's setTimeZone:(refMe's NSTimeZone's timeZoneWithAbbreviation:("UTC")) |
| 084 | set ocidSetDate to ocidFormatter's stringFromDate:(ocidDate) |
| 085 | -->string形式でセットするのでsetValueで |
| 086 | ocidPlistDict's setValue:(ocidSetDate) forKey:("date") |
| 087 | #version |
| 088 | ocidFormatter's setDateFormat:("yyyyMMdd") |
| 089 | set ocidversion to ocidFormatter's stringFromDate:(ocidDate) |
| 090 | ocidPlistDict's setValue:(ocidversion) forKey:("version") |
| 091 |
|
| 092 | ############################## |
| 093 | #containerURLs |
| 094 | set ocidContainerURLsArray to refMe's NSMutableArray's alloc()'s init() |
| 095 | repeat with itemFontURL in ocidFontsPathArray |
| 096 | set ocidItemFontPath to itemFontURL's absoluteString() |
| 097 | (ocidContainerURLsArray's addObject:(ocidItemFontPath)) |
| 098 | end repeat |
| 099 | ocidPlistDict's setObject:(ocidContainerURLsArray) forKey:("containerURLs") |
| 100 | ############################## |
| 101 | #bookmarks |
| 102 | set ocidBookmarks to refMe's NSMutableDictionary's alloc()'s init() |
| 103 | ocidPlistDict's setObject:(ocidBookmarks) forKey:("bookmarks") |
| 104 |
|
| 105 | ##################### |
| 106 | #urlAddedDates |
| 107 | set ocidUrlAddedDatesDict to refMe's NSMutableDictionary's alloc()'s init() |
| 108 | ###フォントのURLを追加(absoluteString形式) |
| 109 | repeat with itemFontPathArray in ocidFontsPathArray |
| 110 | set strPath to (itemFontPathArray's |path|()) |
| 111 | (ocidUrlAddedDatesDict's setValue:(ocidSetDate) forKey:(strPath)) |
| 112 | end repeat |
| 113 | ocidPlistDict's setObject:(ocidUrlAddedDatesDict) forKey:("urlAddedDates") |
| 114 |
|
| 115 | ###################### |
| 116 | #XML形式 |
| 117 | set ocidXmlplist to (refMe's NSPropertyListXMLFormat_v1_0) |
| 118 | #書き込み用にXMLに変換 |
| 119 | set listResponse to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidXmlplist) options:0 |error|:(reference) |
| 120 | set ocidPlistEditData to (first item of listResponse) |
| 121 | #NSDATA |
| 122 | set ocidOption to (refMe's NSDataWritingAtomic) |
| 123 | set listDone to ocidPlistEditData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference) |
| 124 |
|
| 125 | #フォントブックを起動 |
| 126 | tell application id "com.apple.FontBook" |
| 127 | launch |
| 128 | end tell |
| 129 | tell application id "com.apple.FontBook" |
| 130 | activate |
| 131 | end tell |
| 132 |
|
| 133 | return (first item of listDone) |