001 | #!/usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | # com.cocolog-nifty.quicktimer.icefloe |
---|
004 | # ファイル毎にコマンド打ちますのでそれなりに時間かかります |
---|
005 | # 選択したフォントバージョンを取得してHTML表示します |
---|
006 | # python3のセットアップが必要です |
---|
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 framework "UniformTypeIdentifiers" |
---|
013 | use scripting additions |
---|
014 | |
---|
015 | property refMe : a reference to current application |
---|
016 | |
---|
017 | |
---|
018 | ################ |
---|
019 | #python3のパスチェック |
---|
020 | if (doChkPython3()) is false then |
---|
021 | return "python3が見つかりませんでした終了します" |
---|
022 | end if |
---|
023 | |
---|
024 | ################ |
---|
025 | #pythonスクリプトパス |
---|
026 | set aliasPathToMe to (path to me) as alias |
---|
027 | set strPathToMe to (POSIX path of aliasPathToMe) as text |
---|
028 | set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe) |
---|
029 | set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath() |
---|
030 | set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:(false) |
---|
031 | set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent() |
---|
032 | set ocidBinDirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:("bin") isDirectory:(true) |
---|
033 | set ocidPyFilePathURL to ocidBinDirPathURL's URLByAppendingPathComponent:("getNameIdDict.py") isDirectory:(true) |
---|
034 | set strPyFilePathURL to (ocidPyFilePathURL's |path|) as text |
---|
035 | ################ |
---|
036 | #パス |
---|
037 | set strName to (name of current application) as text |
---|
038 | if strName is "osascript" then |
---|
039 | tell application "Finder" to activate |
---|
040 | else |
---|
041 | tell current application to activate |
---|
042 | end if |
---|
043 | ############ デフォルトロケーション |
---|
044 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
045 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
046 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
---|
047 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
---|
048 | |
---|
049 | set listUTI to {"public.opentype-font", "public.truetype-ttf-font", "public.truetype-collection-font", "public.opentype-collection-font", "public.font"} as list |
---|
050 | set strMes to ("ファイルを選んでください") as text |
---|
051 | set strPrompt to ("ファイルを選んでください") as text |
---|
052 | try |
---|
053 | ### ファイル選択時 |
---|
054 | set listAliasFilePath to (choose file strMes with prompt strPrompt default location aliasDefaultLocation of type listUTI with invisibles, multiple selections allowed and showing package contents) as list |
---|
055 | |
---|
056 | on error |
---|
057 | log "エラーしました" |
---|
058 | return "エラーしました" |
---|
059 | end try |
---|
060 | if listAliasFilePath is {} then |
---|
061 | return "選んでください" |
---|
062 | end if |
---|
063 | |
---|
064 | ################ |
---|
065 | # URLDICT作成 |
---|
066 | set ocidFilePathNameDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
067 | |
---|
068 | repeat with itemAliasFilePath in listAliasFilePath |
---|
069 | set aliasFilePath to itemAliasFilePath as alias |
---|
070 | set strFilePath to (POSIX path of aliasFilePath) as text |
---|
071 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
---|
072 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
---|
073 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
---|
074 | # |
---|
075 | set strFileName to ocidFilePathURL's lastPathComponent() as text |
---|
076 | (ocidFilePathNameDict's setObject:(ocidFilePathURL) forKey:(strFileName)) |
---|
077 | end repeat |
---|
078 | |
---|
079 | |
---|
080 | ################ |
---|
081 | # |
---|
082 | set ocidAllKeys to ocidFilePathNameDict's allKeys() |
---|
083 | set ocidSortedAllKey to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:") |
---|
084 | # |
---|
085 | set ocidOutPutDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
086 | # |
---|
087 | repeat with itemKye in ocidSortedAllKey |
---|
088 | set itemFileURL to (ocidFilePathNameDict's objectForKey:(itemKye)) |
---|
089 | |
---|
090 | #修正日 |
---|
091 | set listResponse to (itemFileURL's getResourceValue:(reference) forKey:(refMe's NSURLContentModificationDateKey) |error| :(reference)) |
---|
092 | set ocidModDay to (item 2 of listResponse) |
---|
093 | #ファイルサイズ |
---|
094 | set listResponse to (itemFileURL's getResourceValue:(reference) forKey:(refMe's NSURLFileSizeKey) |error| :(reference)) |
---|
095 | set ocidFileSize to (item 2 of listResponse) |
---|
096 | #コマンド実行 |
---|
097 | set ocidFilePath to (itemFileURL's |path|) |
---|
098 | set ocidFilePathM to ocidFilePath's mutableCopy() |
---|
099 | set ocidFilePathM to (ocidFilePathM's stringByReplacingOccurrencesOfString:("\\") withString:("\\\\\\\\")) |
---|
100 | set ocidFilePathM to (ocidFilePathM's stringByReplacingOccurrencesOfString:("'") withString:("\\'")) |
---|
101 | set ocidFilePathM to (ocidFilePathM's stringByReplacingOccurrencesOfString:("\"") withString:("\\\\\\\"")) |
---|
102 | set strFilePathM to ocidFilePathM as text |
---|
103 | set strCommandText to ("\"" & strPyFilePathURL & "\" \"" & strFilePathM & "\"") as text |
---|
104 | log "\n" & strCommandText & "\n" |
---|
105 | set strExecCommand to ("/bin/zsh -c '" & strCommandText & "'") as text |
---|
106 | try |
---|
107 | set strResponse to (do shell script strExecCommand) as text |
---|
108 | on error |
---|
109 | set strResponse to ("") as text |
---|
110 | end try |
---|
111 | set ocidResponse to (refMe's NSString's stringWithString:(strResponse)) |
---|
112 | set ocidResponeArray to (ocidResponse's componentsSeparatedByString:("\t")) |
---|
113 | set ocidFontFamily to ocidResponeArray's firstObject() |
---|
114 | set ocidFontVersion to ocidResponeArray's lastObject() |
---|
115 | |
---|
116 | #リストにして次工程用のDICTに渡す |
---|
117 | set listValue to {(ocidFilePath), (ocidFileSize), (ocidModDay), (ocidFontFamily), (ocidFontVersion)} as list |
---|
118 | (ocidOutPutDict's setObject:(listValue) forKey:(itemKye)) |
---|
119 | end repeat |
---|
120 | |
---|
121 | ############### |
---|
122 | ## |
---|
123 | set ocidSaveString to refMe's NSMutableString's alloc()'s initWithCapacity:(0) |
---|
124 | (ocidSaveString's appendString:("ファイル名\tファミリ名\tサイズ\t修正日\tバージョン\t備考")) |
---|
125 | (ocidSaveString's appendString:("\n")) |
---|
126 | # |
---|
127 | set ocidAllKeys to ocidOutPutDict's allKeys() |
---|
128 | set ocidSortedAllKey to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:") |
---|
129 | # |
---|
130 | set appDateFormatter to refMe's NSDateFormatter's alloc()'s init() |
---|
131 | (appDateFormatter's setDateFormat:("yyyyMMdd")) |
---|
132 | |
---|
133 | ############################## |
---|
134 | # XML 生成開始 |
---|
135 | ############################## |
---|
136 | set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init() |
---|
137 | (ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)) |
---|
138 | # DTD付与 |
---|
139 | set ocidDTD to refMe's NSXMLDTD's alloc()'s init() |
---|
140 | (ocidDTD's setName:("html")) |
---|
141 | (ocidXMLDoc's setDTD:(ocidDTD)) |
---|
142 | # XML主要部分を生成 |
---|
143 | set ocidRootElement to doMakeRootElement() |
---|
144 | #ボディエレメント |
---|
145 | set ocidBodyElement to (refMe's NSXMLElement's elementWithName:("body")) |
---|
146 | #ヘッダー |
---|
147 | set ocidHeaderElement to (refMe's NSXMLElement's elementWithName:("header")) |
---|
148 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")) |
---|
149 | (ocidHeaderElement's addAttribute:(ocidAddNode)) |
---|
150 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")) |
---|
151 | (ocidHeaderElement's addAttribute:(ocidAddNode)) |
---|
152 | (ocidBodyElement's addChild:(ocidHeaderElement)) |
---|
153 | #アーティクル |
---|
154 | set ocidArticleElement to (refMe's NSXMLElement's elementWithName:("article")) |
---|
155 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")) |
---|
156 | (ocidArticleElement's addAttribute:(ocidAddNode)) |
---|
157 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")) |
---|
158 | (ocidArticleElement's addAttribute:(ocidAddNode)) |
---|
159 | (ocidBodyElement's addChild:(ocidArticleElement)) |
---|
160 | #フッター |
---|
161 | set ocidFooterElement to (refMe's NSXMLElement's elementWithName:("footer")) |
---|
162 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")) |
---|
163 | (ocidFooterElement's addAttribute:(ocidAddNode)) |
---|
164 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")) |
---|
165 | (ocidFooterElement's addAttribute:(ocidAddNode)) |
---|
166 | #リンク付与(不要なら削除可) |
---|
167 | set ocidAElement to (refMe's NSXMLElement's elementWithName:("a")) |
---|
168 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/")) |
---|
169 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
170 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
---|
171 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
172 | set strContents to ("AppleScriptで生成しました") as text |
---|
173 | (ocidAElement's setStringValue:(strContents)) |
---|
174 | (ocidFooterElement's addChild:(ocidAElement)) |
---|
175 | (ocidBodyElement's addChild:(ocidFooterElement)) |
---|
176 | ############################## |
---|
177 | # TABLE コンテンツ部分生成開始 |
---|
178 | ############################## |
---|
179 | #テーブル部生成開始 |
---|
180 | set ocidTableElement to (refMe's NSXMLElement's elementWithName:("table")) |
---|
181 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("summary") stringValue:("フォントのバージョン一覧 フォントの各項目の値が一覧になっています")) |
---|
182 | (ocidTableElement's addAttribute:(ocidAddNode)) |
---|
183 | |
---|
184 | #【caption】 |
---|
185 | set ocidCaptionElement to (refMe's NSXMLElement's elementWithName:("caption")) |
---|
186 | (ocidCaptionElement's setStringValue:("【ファイルリスト】: フォントリスト")) |
---|
187 | (ocidTableElement's addChild:(ocidCaptionElement)) |
---|
188 | #【colgroup】 |
---|
189 | set ocidColgroupElement to (refMe's NSXMLElement's elementWithName:("colgroup")) |
---|
190 | #テーブルのタイトル部 |
---|
191 | set listColName to {"行番号", "ファイル名", "ファミリー名", "サイズ", "修正日", "バージョン", "備考"} as list |
---|
192 | set listColID to {"liineNO", "FileName", "FontFamilyName", "FileSize", "ModDay", "Version", "Note"} as list |
---|
193 | #項目数を取得して |
---|
194 | set numCntCol to (count of listColName) as integer |
---|
195 | #タイトル部の数だけ繰り返し |
---|
196 | repeat with itemNo from 1 to numCntCol by 1 |
---|
197 | set strItemName to (item itemNo of listColName) as text |
---|
198 | #【col】col生成 |
---|
199 | set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col")) |
---|
200 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strItemName)) |
---|
201 | (ocidAddElement's addAttribute:(ocidAddNode)) |
---|
202 | (ocidColgroupElement's addChild:(ocidAddElement)) |
---|
203 | end repeat |
---|
204 | #テーブルエレメントに追加 |
---|
205 | (ocidTableElement's addChild:(ocidColgroupElement)) |
---|
206 | #【thead】 |
---|
207 | set ocidTheadElement to (refMe's NSXMLElement's elementWithName:("thead")) |
---|
208 | #TR |
---|
209 | set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr")) |
---|
210 | #タイトル部の数だけ繰り返し |
---|
211 | repeat with itemNo from 1 to numCntCol by 1 |
---|
212 | set strItemName to (item itemNo of listColName) as text |
---|
213 | set strItemID to (item itemNo of listColID) as text |
---|
214 | #ここはTDではなくてTHを利用 |
---|
215 | set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th")) |
---|
216 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strItemName)) |
---|
217 | (ocidAddElement's addAttribute:(ocidAddNode)) |
---|
218 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:(strItemID)) |
---|
219 | (ocidAddElement's addAttribute:(ocidAddNode)) |
---|
220 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col")) |
---|
221 | (ocidAddElement's addAttribute:(ocidAddNode)) |
---|
222 | #値を入れる |
---|
223 | (ocidAddElement's setStringValue:(strItemName)) |
---|
224 | #TH→TRにセット |
---|
225 | (ocidTrElement's addChild:(ocidAddElement)) |
---|
226 | end repeat |
---|
227 | #TRをTHEADにセット |
---|
228 | (ocidTheadElement's addChild:(ocidTrElement)) |
---|
229 | #THEADをテーブルにセット |
---|
230 | (ocidTableElement's addChild:(ocidTheadElement)) |
---|
231 | |
---|
232 | ############ |
---|
233 | #【tbody】 |
---|
234 | set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody") |
---|
235 | set numCntLineNo to 1 as integer |
---|
236 | repeat with itemKey in ocidSortedAllKey |
---|
237 | set ocidItemArray to (ocidOutPutDict's objectForKey:(itemKey)) |
---|
238 | set strFileName to itemKey as text |
---|
239 | #URL サイズ 修正日 バージョン |
---|
240 | set ocidUrl to (ocidItemArray's objectAtIndex:(0)) |
---|
241 | set ocidSize to (ocidItemArray's objectAtIndex:(1)) |
---|
242 | set ocidMod to (ocidItemArray's objectAtIndex:(2)) |
---|
243 | set ocidFamily to (ocidItemArray's objectAtIndex:(3)) |
---|
244 | set ocidVer to (ocidItemArray's objectAtIndex:(4)) |
---|
245 | # |
---|
246 | set strColName1 to (item 1 of listColName) as text |
---|
247 | set strColName2 to (item 2 of listColName) as text |
---|
248 | set strColName3 to (item 3 of listColName) as text |
---|
249 | set strColName4 to (item 4 of listColName) as text |
---|
250 | set strColName5 to (item 5 of listColName) as text |
---|
251 | set strColName6 to (item 6 of listColName) as text |
---|
252 | set strColName7 to (item 7 of listColName) as text |
---|
253 | # |
---|
254 | set strItemID1 to (item 1 of listColID) as text |
---|
255 | set strItemID2 to (item 2 of listColID) as text |
---|
256 | set strItemID3 to (item 3 of listColID) as text |
---|
257 | set strItemID4 to (item 4 of listColID) as text |
---|
258 | set strItemID5 to (item 5 of listColID) as text |
---|
259 | set strItemID6 to (item 6 of listColID) as text |
---|
260 | set strItemID7 to (item 7 of listColID) as text |
---|
261 | # |
---|
262 | set ocidUrlStr to (refMe's NSString's stringWithString:(ocidUrl)) |
---|
263 | set ocidUrlPath to ocidUrlStr's stringByStandardizingPath() |
---|
264 | set ocidLinkURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidUrlPath) isDirectory:false) |
---|
265 | set strAbsoluteString to ocidLinkURL's absoluteString() as text |
---|
266 | set strModDateStr to (appDateFormatter's stringFromDate:(ocidMod)) as text |
---|
267 | |
---|
268 | set ocidVer to (ocidVer's stringByReplacingOccurrencesOfString:("Version ") withString:("")) |
---|
269 | set ocidVer to (ocidVer's stringByReplacingOccurrencesOfString:("version ") withString:("")) |
---|
270 | set ocidVer to (ocidVer's stringByReplacingOccurrencesOfString:("Version") withString:("")) |
---|
271 | set ocidVer to (ocidVer's stringByReplacingOccurrencesOfString:("version") withString:("")) |
---|
272 | ######## |
---|
273 | #TRの開始 |
---|
274 | set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr")) |
---|
275 | #【行番号】をTHでセット |
---|
276 | set strZeroSupp to ("00") as text |
---|
277 | set strZeroSupp to ("00" & numCntLineNo) as text |
---|
278 | set strLineNO to (text -3 through -1 of strZeroSupp) as text |
---|
279 | set ocidThElement to (refMe's NSXMLElement's elementWithName:("th")) |
---|
280 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName1)) |
---|
281 | (ocidThElement's addAttribute:(ocidAddNode)) |
---|
282 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row")) |
---|
283 | (ocidThElement's addAttribute:(ocidAddNode)) |
---|
284 | set strSetValue to ("LineNO" & strLineNO) as text |
---|
285 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:(strSetValue)) |
---|
286 | (ocidThElement's addAttribute:(ocidAddNode)) |
---|
287 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strItemID1)) |
---|
288 | (ocidThElement's addAttribute:(ocidAddNode)) |
---|
289 | (ocidThElement's setStringValue:(strLineNO)) |
---|
290 | (ocidTrElement's addChild:(ocidThElement)) |
---|
291 | ######## |
---|
292 | #【ファイル名】をTDでセット |
---|
293 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
---|
294 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName2)) |
---|
295 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
296 | set strSetValue to (strFileName & " " & strItemID2) as text |
---|
297 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue)) |
---|
298 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
299 | # |
---|
300 | set ocidAElement to (refMe's NSXMLElement's elementWithName:("a")) |
---|
301 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("alt") stringValue:(strFileName)) |
---|
302 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
303 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strAbsoluteString)) |
---|
304 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
305 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
---|
306 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
307 | (ocidAElement's setStringValue:(strFileName)) |
---|
308 | #リンクをTDにセット |
---|
309 | (ocidTdElement's addChild:(ocidAElement)) |
---|
310 | #TDをTRにセット |
---|
311 | (ocidTrElement's addChild:(ocidTdElement)) |
---|
312 | ############ |
---|
313 | #【見本】をTDでセット |
---|
314 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
---|
315 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName3)) |
---|
316 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
317 | set strSetValue to (strFileName & " " & strItemID3) as text |
---|
318 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strItemID3)) |
---|
319 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
320 | # |
---|
321 | set ocidSpanElement to (refMe's NSXMLElement's elementWithName:("span")) |
---|
322 | set strSetValue to ("font-family: '" & ocidFamily & "', sans-serif;") as text |
---|
323 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:(strSetValue)) |
---|
324 | (ocidSpanElement's addAttribute:(ocidAddNode)) |
---|
325 | set strSetValue to (ocidFamily) as text |
---|
326 | (ocidSpanElement's setStringValue:(strSetValue)) |
---|
327 | (ocidTdElement's addChild:(ocidSpanElement)) |
---|
328 | (ocidTrElement's addChild:(ocidTdElement)) |
---|
329 | ############ |
---|
330 | #【ファイルサイズ】TD |
---|
331 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
---|
332 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName4)) |
---|
333 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
334 | set strSetValue to (strFileName & " " & strItemID4) as text |
---|
335 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue)) |
---|
336 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
337 | #単位による分岐 |
---|
338 | set strValue to ocidSize as text |
---|
339 | set numFileSize to strValue as integer |
---|
340 | # |
---|
341 | set numByteUnits to 1000 as integer |
---|
342 | # バイト単位 10.5以前やWindowsターゲットの場合は1024に |
---|
343 | if (numFileSize) < numByteUnits then |
---|
344 | log "b:バイト単位" |
---|
345 | set strFileSize to doRound2Dec(numFileSize) |
---|
346 | set strValue to (strFileSize & " b") as text |
---|
347 | else if numFileSize < (numByteUnits * numByteUnits) then |
---|
348 | log "kb:キロバイト単位" |
---|
349 | set strFileSize to doRound2Dec(numFileSize / numByteUnits) |
---|
350 | set strValue to (strFileSize & " kb") as text |
---|
351 | else if numFileSize < (numByteUnits * numByteUnits * numByteUnits) then |
---|
352 | log "mb:メガバイト単位" |
---|
353 | set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits)) |
---|
354 | set strValue to (strFileSize & " mb") as text |
---|
355 | else |
---|
356 | log "gb:ギガバイト単位" |
---|
357 | set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits * numByteUnits)) |
---|
358 | set strValue to (strFileSize & " gb") as text |
---|
359 | end if |
---|
360 | (ocidTdElement's setStringValue:(strValue)) |
---|
361 | (ocidTrElement's addChild:(ocidTdElement)) |
---|
362 | ######## |
---|
363 | #【修正日】をTDでセット |
---|
364 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
---|
365 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName5)) |
---|
366 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
367 | set strSetValue to (strFileName & " " & strItemID5) as text |
---|
368 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue)) |
---|
369 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
370 | (ocidTdElement's setStringValue:(strModDateStr)) |
---|
371 | #TDをTRにセット |
---|
372 | (ocidTrElement's addChild:(ocidTdElement)) |
---|
373 | ######## |
---|
374 | #【バージョン】をTDでセット |
---|
375 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
---|
376 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName6)) |
---|
377 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
378 | set strSetValue to (strFileName & " " & strItemID6) as text |
---|
379 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue)) |
---|
380 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
381 | (ocidTdElement's setStringValue:(ocidVer)) |
---|
382 | #TDをTRにセット |
---|
383 | (ocidTrElement's addChild:(ocidTdElement)) |
---|
384 | ######## |
---|
385 | #【備考】をTDでセット |
---|
386 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
---|
387 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName7)) |
---|
388 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
389 | set strSetValue to (strFileName & " " & strItemID7) as text |
---|
390 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue)) |
---|
391 | (ocidTdElement's addAttribute:(ocidAddNode)) |
---|
392 | (ocidTdElement's setStringValue:("")) |
---|
393 | #TDをTRにセット |
---|
394 | (ocidTrElement's addChild:(ocidTdElement)) |
---|
395 | #出来上がったTRをTBODYにセット |
---|
396 | (ocidTbodyElement's addChild:(ocidTrElement)) |
---|
397 | # |
---|
398 | set numCntLineNo to (numCntLineNo + 1) as integer |
---|
399 | end repeat |
---|
400 | ######## |
---|
401 | #TBODYをテーブルにセット |
---|
402 | (ocidTableElement's addChild:(ocidTbodyElement)) |
---|
403 | ############ |
---|
404 | #【tfoot】 TRで |
---|
405 | set ocidTfootElement to (refMe's NSXMLElement's elementWithName:("tfoot")) |
---|
406 | set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr")) |
---|
407 | #colspan指定して1行でセット |
---|
408 | set ocidThElement to (refMe's NSXMLElement's elementWithName:("th")) |
---|
409 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり")) |
---|
410 | (ocidThElement's addAttribute:(ocidAddNode)) |
---|
411 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text)) |
---|
412 | (ocidThElement's addAttribute:(ocidAddNode)) |
---|
413 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row")) |
---|
414 | (ocidThElement's addAttribute:(ocidAddNode)) |
---|
415 | (ocidThElement's setStringValue:("TTC等のコレクションフォントは代表で1つのみ表示しています")) |
---|
416 | #THをTRにセットして |
---|
417 | (ocidTrElement's addChild:(ocidThElement)) |
---|
418 | #TRをTFOOTにセット |
---|
419 | (ocidTfootElement's addChild:(ocidTrElement)) |
---|
420 | #TFOOTをテーブルにセット |
---|
421 | (ocidTableElement's addChild:(ocidTfootElement)) |
---|
422 | ############################## |
---|
423 | # ROOT |
---|
424 | ############################## |
---|
425 | # 出来上がったテーブルをArticleエレメントにセット |
---|
426 | (ocidArticleElement's addChild:(ocidTableElement)) |
---|
427 | # |
---|
428 | (ocidRootElement's addChild:(ocidBodyElement)) |
---|
429 | #ROOTエレメントをXMLにセット |
---|
430 | ocidXMLDoc's setRootElement:(ocidRootElement) |
---|
431 | #読み取りやすい表示 |
---|
432 | set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint) |
---|
433 | |
---|
434 | |
---|
435 | |
---|
436 | #################### |
---|
437 | ## |
---|
438 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
439 | set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser() |
---|
440 | set ocidSaveDirPathURL to ocidHomeDirURL's URLByAppendingPathComponent:("Sites/FontList") isDirectory:(true) |
---|
441 | # |
---|
442 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
443 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
---|
444 | set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
---|
445 | # |
---|
446 | set strDateNo to doGetNextDateNo({"yyyyMMdd-hhmm", 1}) |
---|
447 | |
---|
448 | set strFileName to ("FontList." & strDateNo & ".html") as text |
---|
449 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false |
---|
450 | #保存 |
---|
451 | set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference) |
---|
452 | if (item 1 of listDone) is true then |
---|
453 | log "正常終了" |
---|
454 | else if (item 1 of listDone) is false then |
---|
455 | log (item 2 of listDone)'s localizedDescription() as text |
---|
456 | return "保存に失敗しました" |
---|
457 | end if |
---|
458 | set ocidSaveFilePath to ocidSaveFilePathURL's |path| |
---|
459 | set ocidContainerDirPath to ocidSaveDirPathURL's |path| |
---|
460 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
---|
461 | set boolDone to appSharedWorkspace's selectFile:(ocidSaveFilePath) inFileViewerRootedAtPath:(ocidContainerDirPath) |
---|
462 | set boolDone to appSharedWorkspace's openURL:(ocidSaveFilePathURL) |
---|
463 | if (boolDone as boolean) is false then |
---|
464 | #ファイルを開く |
---|
465 | set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias |
---|
466 | tell application "Finder" |
---|
467 | open file aliasSaveFilePath |
---|
468 | end tell |
---|
469 | end if |
---|
470 | |
---|
471 | |
---|
472 | |
---|
473 | |
---|
474 | ############################## |
---|
475 | ## python3のパスチェック |
---|
476 | ############################## |
---|
477 | to doChkPython3() |
---|
478 | try |
---|
479 | set strCmdText to ("/usr/bin/which python3") as text |
---|
480 | set strBinPath to (do shell script strCmdText) as text |
---|
481 | return true |
---|
482 | on error |
---|
483 | return false |
---|
484 | end try |
---|
485 | end doChkPython3 |
---|
486 | |
---|
487 | ############################## |
---|
488 | # 基本的なHTMLの構造 |
---|
489 | ############################## |
---|
490 | to doMakeRootElement() |
---|
491 | # |
---|
492 | set ocidRootElement to refMe's NSXMLElement's elementWithName:("html") |
---|
493 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja") |
---|
494 | ocidRootElement's addAttribute:(ocidAddNode) |
---|
495 | # |
---|
496 | set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head") |
---|
497 | # |
---|
498 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("title") |
---|
499 | ocidAddElement's setStringValue:("フォント一覧") |
---|
500 | ocidHeadElement's addChild:(ocidAddElement) |
---|
501 | # http-equiv |
---|
502 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
---|
503 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type") |
---|
504 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
505 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8") |
---|
506 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
507 | ocidHeadElement's addChild:(ocidAddElement) |
---|
508 | # |
---|
509 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
---|
510 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type") |
---|
511 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
512 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css") |
---|
513 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
514 | ocidHeadElement's addChild:(ocidAddElement) |
---|
515 | # |
---|
516 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
---|
517 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type") |
---|
518 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
519 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript") |
---|
520 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
521 | ocidHeadElement's addChild:(ocidAddElement) |
---|
522 | # |
---|
523 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
---|
524 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport") |
---|
525 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
526 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720") |
---|
527 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
528 | ocidHeadElement's addChild:(ocidAddElement) |
---|
529 | # |
---|
530 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("style") |
---|
531 | ocidAddElement's setStringValue:("body { margin: 10px; background-color: #FFFFFF; } table { border-spacing: 0; caption-side: top; font-family: system-ui; } thead th { border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:first-of-type { border-start-start-radius: .5em } &:last-of-type { border-start-end-radius: .5em; border-inline-end-width: 1px } } tbody td { word-wrap: break-word;max-width: 360px;border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; &:last-of-type { border-inline-end-width: 1px } } tbody p { margin-block-end: 2px; margin-block-start: 2px;} tbody th { border-spacing: 0; border: solid 1px #666666; padding: .5ch 1ch; border-block-width: 1px 0; border-inline-width: 1px 0; } tbody tr:nth-of-type(odd) { background: #F2F2F2; } .kind_string { font-size: 0.75em; } .date_string { font-size: 0.5em; } tfoot th { border: solid 1px #666666; padding: .5ch 1ch; &:first-of-type { border-end-start-radius: .5em } &:last-of-type { border-end-end-radius: .5em; border-inline-end-width: 1px } }") |
---|
532 | ocidHeadElement's addChild:(ocidAddElement) |
---|
533 | # |
---|
534 | ocidRootElement's addChild:(ocidHeadElement) |
---|
535 | # |
---|
536 | return ocidRootElement |
---|
537 | end doMakeRootElement |
---|
538 | |
---|
539 | ############################## |
---|
540 | # 小数点以下2桁処理 |
---|
541 | ############################## |
---|
542 | |
---|
543 | to doRound2Dec(argNumber) |
---|
544 | set strDecNo to ((round (argNumber * 100)) / 100) as text |
---|
545 | return strDecNo |
---|
546 | end doRound2Dec |
---|
547 | |
---|
548 | ################################ |
---|
549 | # 明日の日付 doGetDateNo(argDateFormat,argCalendarNO) |
---|
550 | # argCalendarNO 1 NSCalendarIdentifierGregorian 西暦 |
---|
551 | # argCalendarNO 2 NSCalendarIdentifierJapanese 和暦 |
---|
552 | ################################ |
---|
553 | to doGetNextDateNo({argDateFormat, argCalendarNO}) |
---|
554 | ##渡された値をテキストで確定させて |
---|
555 | set strDateFormat to argDateFormat as text |
---|
556 | set intCalendarNO to argCalendarNO as integer |
---|
557 | ###日付情報の取得 |
---|
558 | set ocidDate to current application's NSDate's |date|() |
---|
559 | set ocidIntervalt to current application's NSDate's dateWithTimeIntervalSinceNow:(86400) |
---|
560 | ###日付のフォーマットを定義(日本語) |
---|
561 | set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init() |
---|
562 | ###和暦 西暦 カレンダー分岐 |
---|
563 | if intCalendarNO = 1 then |
---|
564 | set ocidCalendarID to (current application's NSCalendarIdentifierGregorian) |
---|
565 | else if intCalendarNO = 2 then |
---|
566 | set ocidCalendarID to (current application's NSCalendarIdentifierJapanese) |
---|
567 | else |
---|
568 | set ocidCalendarID to (current application's NSCalendarIdentifierISO8601) |
---|
569 | end if |
---|
570 | set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID) |
---|
571 | set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo") |
---|
572 | set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX") |
---|
573 | ###設定 |
---|
574 | ocidFormatterJP's setTimeZone:(ocidTimezoneJP) |
---|
575 | ocidFormatterJP's setLocale:(ocidLocaleJP) |
---|
576 | ocidFormatterJP's setCalendar:(ocidCalendarJP) |
---|
577 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle) |
---|
578 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle) |
---|
579 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle) |
---|
580 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle) |
---|
581 | ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle) |
---|
582 | ###渡された値でフォーマット定義 |
---|
583 | ocidFormatterJP's setDateFormat:(strDateFormat) |
---|
584 | ###フォーマット適応 |
---|
585 | set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidIntervalt) |
---|
586 | ###テキストで戻す |
---|
587 | set strDateAndTime to ocidDateAndTime as text |
---|
588 | return strDateAndTime |
---|
589 | end doGetNextDateNo |
---|