Illustratorの合成フォントファイルから使用されているフォント名を表示する
あくまでも参考にしてください
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | (* |
004 | 合成フォントファイル(書き出し保存したもの)を調べて |
005 | 含まれているフォント名を表示します |
006 | com.cocolog-nifty.quicktimer.icefloe |
007 | *) |
008 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
009 | use AppleScript version "2.8" |
010 | use framework "Foundation" |
011 | use framework "AppKit" |
012 | use scripting additions |
013 | |
014 | property refMe : a reference to current application |
015 | set boolDirExists to false as boolean |
016 | |
017 | |
018 | ##使用中のバージョン |
019 | set listVersion to {"28", "27", "26"} as list |
020 | |
021 | ###デフォルトロケーションタイプBアプリケーションサポート |
022 | set appFileManager to refMe's NSFileManager's defaultManager() |
023 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSApplicationSupportDirectory) inDomains:(refMe's NSUserDomainMask)) |
024 | set ocidApplicatioocidupportDirPathURL to ocidURLsArray's firstObject() |
025 | repeat with itemVarsion in listVersion |
026 | set ocidDirPathURL to (ocidApplicatioocidupportDirPathURL's URLByAppendingPathComponent:("Adobe/Adobe Illustrator " & itemVarsion & "/ja_JP/合成フォント")) |
027 | set ocidDirPath to ocidDirPathURL's |path|() |
028 | set boolDirExists to (appFileManager's fileExistsAtPath:(ocidDirPath) isDirectory:(true)) |
029 | if boolDirExists is true then |
030 | set aliasDefaultLocation to (ocidDirPathURL's absoluteURL()) as alias |
031 | exit repeat |
032 | end if |
033 | end repeat |
034 | if boolDirExists is false then |
035 | ### デフォルトロケーションタイプAデスクトップ |
036 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
037 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
038 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
039 | end if |
040 | set listUTI to {"public.data"} |
041 | set strMes to ("合成フォントファイルを選んでください") as text |
042 | set strPrompt to ("合成フォントファイルを選んでください") as text |
043 | try |
044 | ### ファイル選択時 |
045 | set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasDefaultLocation) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias |
046 | on error |
047 | log "エラーしました" |
048 | return "エラーしました" |
049 | end try |
050 | |
051 | #パス |
052 | set strFilePath to (POSIX path of aliasFilePath) as text |
053 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
054 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
055 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
056 | #データ読み込み |
057 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
058 | set listResponse to refMe's NSData's dataWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error| :(reference) |
059 | if (item 2 of listResponse) ≠ (missing value) then |
060 | log (item 2 of listResponse)'s localizedDescription() as text |
061 | return "Data読み込みでエラーしました" |
062 | else if (item 2 of listResponse) = (missing value) then |
063 | set ocidReadData to (item 1 of listResponse) |
064 | end if |
065 | #ここの100は調整する必要があるかも |
066 | #テキストにするために不要な部分を削除 |
067 | set numOffSet to 100 as integer |
068 | set ocidDataLength to ocidReadData's |length|() |
069 | set ocidRage to refMe's NSRange's NSMakeRange(numOffSet, (ocidDataLength - numOffSet)) |
070 | repeat |
071 | #レンジの幅のみのデータを受け取り |
072 | set ocidTrimData to ocidReadData's subdataWithRange:(ocidRage) |
073 | #テキストに変換 |
074 | set ocidReadText to refMe's NSString's alloc()'s initWithData:(ocidTrimData) encoding:(refMe's NSUTF8StringEncoding) |
075 | #エラーがなくなるまで繰り返し |
076 | if ocidReadText = (missing value) then |
077 | #ファイルの末尾の読み込みを削っていく |
078 | set ocidDataLength to ocidDataLength - 100 |
079 | #レンジにして |
080 | set ocidRage to refMe's NSRange's NSMakeRange(numOffSet, (ocidDataLength)) |
081 | else |
082 | exit repeat |
083 | end if |
084 | end repeat |
085 | |
086 | #出力用のテキスト |
087 | set ocidOutPutstring to refMe's NSMutableString's alloc()'s initWithCapacity:(0) |
088 | #テキストにしたデータを改行毎リストに |
089 | set ocidChrSet to refMe's NSCharacterSet's characterSetWithCharactersInString:("\r\n") |
090 | set ocidReadArray to ocidReadText's componentsSeparatedByCharactersInSet:(ocidChrSet) |
091 | #合成フォントIDを取得 |
092 | repeat with itemLine in ocidReadArray |
093 | set boolContain to (itemLine's hasPrefix:("%%BeginResource:")) |
094 | if boolContain is true then |
095 | set ocidInsText to (itemLine's stringByReplacingOccurrencesOfString:("%%BeginResource: Font ") withString:("合成フォントID\n")) |
096 | (ocidOutPutstring's appendString:(ocidInsText)) |
097 | (ocidOutPutstring's appendString:("\n")) |
098 | end if |
099 | end repeat |
100 | #ソートして |
101 | set ocidSelf to refMe's NSString's stringWithString:("self") |
102 | set ocidSortedArray to ocidReadArray's sortedArrayUsingSelector:"localizedCaseInsensitiveCompare:" |
103 | #可変リストにセット |
104 | set ocidSortedArrayM to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
105 | ocidSortedArrayM's addObjectsFromArray:(ocidSortedArray) |
106 | ####重複行削除と不要行削除 |
107 | set numCntArray to ocidSortedArrayM's |count|() |
108 | repeat with itemIntNo from (numCntArray - 1) to 1 by -1 |
109 | set ocidLineText to (ocidSortedArrayM's objectAtIndex:(itemIntNo)) |
110 | set boolContain to (ocidLineText's hasPrefix:("%%+ Font")) |
111 | if boolContain is true then |
112 | set strNextText to (ocidSortedArrayM's objectAtIndex:(itemIntNo - 1)) as text |
113 | if (ocidLineText as text) is strNextText then |
114 | (ocidSortedArrayM's removeObjectAtIndex:(itemIntNo)) |
115 | end if |
116 | else |
117 | (ocidSortedArrayM's removeObjectAtIndex:(itemIntNo)) |
118 | end if |
119 | end repeat |
120 | (ocidSortedArrayM's removeObjectAtIndex:(0)) |
121 | |
122 | #戻り値用にテキストを整形 |
123 | (ocidOutPutstring's appendString:("使用されているフォント")) |
124 | (ocidOutPutstring's appendString:("\n")) |
125 | ###置換 |
126 | repeat with itemArray in ocidSortedArrayM |
127 | set ocidPsFontName to (itemArray's stringByReplacingOccurrencesOfString:("%%+ Font ") withString:("")) |
128 | (ocidOutPutstring's appendString:(ocidPsFontName)) |
129 | (ocidOutPutstring's appendString:("\n")) |
130 | end repeat |
131 | ############################## |
132 | #####ダイアログ |
133 | ############################## |
134 | tell current application |
135 | set strName to name as text |
136 | end tell |
137 | if strName is "osascript" then |
138 | tell application "Finder" |
139 | activate |
140 | end tell |
141 | else |
142 | tell current application |
143 | activate |
144 | end tell |
145 | end if |
146 | set aliasIconPath to (POSIX file "/Applications/Utilities/Adobe Sync/CoreSync/Core Sync.app/Contents/Resources/CreativeCloudIcons.icns") as alias |
147 | set strMes to "Postscriptフォント名です" |
148 | try |
149 | set recordResult to (display dialog strMes with title "戻り値です" default answer (ocidOutPutstring as text) buttons {"クリップボードにコピー", "終了", "再実行"} default button "再実行" cancel button "終了" giving up after 20 with icon aliasIconPath without hidden answer) as record |
150 | on error |
151 | return "エラーしました" |
152 | end try |
153 | if (gave up of recordResult) is true then |
154 | return "時間切れです" |
155 | end if |
156 | ############################## |
157 | #####自分自身を再実行 |
158 | ############################## |
159 | if button returned of recordResult is "再実行" then |
160 | tell application "Finder" |
161 | set aliasPathToMe to (path to me) as alias |
162 | end tell |
163 | run script aliasPathToMe with parameters "再実行" |
164 | end if |
165 | ############################## |
166 | #####値のコピー |
167 | ############################## |
168 | if button returned of recordResult is "クリップボードにコピー" then |
169 | try |
170 | set strText to text returned of recordResult as text |
171 | ####ペーストボード宣言 |
172 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
173 | set ocidText to (refMe's NSString's stringWithString:(strText)) |
174 | appPasteboard's clearContents() |
175 | appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString) |
176 | on error |
177 | tell application "Finder" |
178 | set the clipboard to strText as text |
179 | end tell |
180 | end try |
181 | end if |
182 | |
183 | |
184 | return 0 |
AppleScriptで生成しました |
| 固定リンク