フォルダ内のファイルの情報をHTMLで出力する 少し修正
ダウンロード - makefilelist2html.zip
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | # 別名で保存から アプリケーションで保存でドロップレットになります |
005 | # v2 一部のメディアのピクセルサイズの取得に対応 |
006 | # com.cocolog-nifty.quicktimer.icefloe |
007 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
008 | use AppleScript version "2.8" |
009 | use framework "Foundation" |
010 | use framework "AppKit" |
011 | use framework "UniformTypeIdentifiers" |
012 | use framework "AVFoundation" |
013 | use framework "CoreMedia" |
014 | use scripting additions |
015 | property refMe : a reference to current application |
016 | |
017 | |
018 | ###Wクリックで起動した場合 |
019 | on run |
020 | ###ダイアログを前面に出す |
021 | tell current application |
022 | set strName to name as text |
023 | end tell |
024 | ####スクリプトメニューから実行したら |
025 | if strName is "osascript" then |
026 | tell application "Finder" to activate |
027 | else |
028 | tell current application to activate |
029 | end if |
030 | ##デフォルト=デスクトップ |
031 | set appFileManager to refMe's NSFileManager's defaultManager() |
032 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
033 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
034 | set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias |
035 | set strPromptText to "フォルダをえらんでください" |
036 | set strMesText to "フォルダをえらんでください" |
037 | try |
038 | set aliasDirPath to (choose folder strMesText with prompt strPromptText default location aliasDesktopDirPath with invisibles and showing package contents without multiple selections allowed) as alias |
039 | on error |
040 | log "エラーしました" |
041 | return "エラーしました" |
042 | end try |
043 | open aliasDirPath |
044 | end run |
045 | |
046 | |
047 | on open aliasDirPath |
048 | ##パス |
049 | set aliasDirPath to aliasDirPath as alias |
050 | set strDirPath to (POSIX path of aliasDirPath) as text |
051 | set ocidDirPathStr to refMe's NSString's stringWithString:(strDirPath) |
052 | set ocidDirPath to ocidDirPathStr's stringByStandardizingPath() |
053 | set ocidDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPath) |
054 | set strDirPathURL to ocidDirPathURL's absoluteString() as text |
055 | ##フォルダ判定 |
056 | set listBoole to (ocidDirPathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error| :(reference)) |
057 | set boolIsDir to (item 2 of listBoole) as boolean |
058 | if boolIsDir is false then |
059 | return "フォルダ以外です処理を終了します" |
060 | end if |
061 | ##フォルダ名→保存先HTMLパス |
062 | set ocidDirName to ocidDirPathURL's lastPathComponent() |
063 | set ocidSaveFileName to refMe's NSMutableString's alloc()'s initWithCapacity:0 |
064 | ocidSaveFileName's appendString:("_ファイルリスト") |
065 | ocidSaveFileName's appendString:(ocidDirName) |
066 | set ocidBaseFilePathURL to ocidDirPathURL's URLByAppendingPathComponent:(ocidSaveFileName) |
067 | set ocidSaveFilePathURL to ocidBaseFilePathURL's URLByAppendingPathExtension:("html") |
068 | |
069 | ##ファイルの各種プロパティを取得 |
070 | set appFileManager to refMe's NSFileManager's defaultManager() |
071 | set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles |
072 | set ocidPropertieArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
073 | ocidPropertieArray's addObject:(refMe's NSURLPathKey) |
074 | ocidPropertieArray's addObject:(refMe's NSURLFileSizeKey) |
075 | ocidPropertieArray's addObject:(refMe's NSURLCreationDateKey) |
076 | ocidPropertieArray's addObject:(refMe's NSURLContentModificationDateKey) |
077 | ocidPropertieArray's addObject:(refMe's NSURLNameKey) |
078 | ocidPropertieArray's addObject:(refMe's NSURLContentTypeKey) |
079 | ocidPropertieArray's addObject:(refMe's NSURLFileAllocatedSizeKey) |
080 | ocidPropertieArray's addObject:(refMe's NSURLIsRegularFileKey) |
081 | ######################################## |
082 | ##コンテンツの収集 A 第一階層のみの場合 |
083 | ######################################## |
084 | (* |
085 | set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidDirPathURL) includingPropertiesForKeys:(ocidPropertieArray) options:(ocidOption) |error| :(reference)) |
086 | set ocidFilePathURLArray to item 1 of listResponse |
087 | #パスリストをファイル名でソート並び替え |
088 | set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("lastPathComponent") ascending:(yes) selector:("localizedStandardCompare:") |
089 | set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor) |
090 | set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray) |
091 | *) |
092 | ######################################## |
093 | ##コンテンツの収集 B 最下層までの場合 |
094 | ######################################## |
095 | set ocidEmuDict to appFileManager's enumeratorAtURL:(ocidDirPathURL) includingPropertiesForKeys:(ocidPropertieArray) options:(ocidOption) errorHandler:(reference) |
096 | set ocidEmuFileURLArray to ocidEmuDict's allObjects() |
097 | set ocidFilePathURLAllArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0) |
098 | ocidFilePathURLAllArray's addObjectsFromArray:(ocidEmuFileURLArray) |
099 | # |
100 | set ocidFilePathURLArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0) |
101 | repeat with itemFilePathURL in ocidFilePathURLAllArray |
102 | set listResult to (itemFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error| :(reference)) |
103 | set boolIsRegularFileKey to item 2 of listResult |
104 | if boolIsRegularFileKey is (refMe's NSNumber's numberWithBool:true) then |
105 | ####リストにする |
106 | (ocidFilePathURLArray's addObject:(itemFilePathURL)) |
107 | end if |
108 | end repeat |
109 | #パスリストをファイル名でソート並び替え absoluteString localizedStandardCompare |
110 | set ocidDescriptor to (refMe's NSSortDescriptor's sortDescriptorWithKey:"path" ascending:(true) selector:"localizedStandardCompare:") |
111 | set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor) |
112 | set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray) |
113 | |
114 | ############################## |
115 | # XML 生成開始 |
116 | ############################## |
117 | #XML初期化 |
118 | set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init() |
119 | ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind) |
120 | # DTD付与 |
121 | set ocidDTD to refMe's NSXMLDTD's alloc()'s init() |
122 | ocidDTD's setName:("html") |
123 | ocidXMLDoc's setDTD:(ocidDTD) |
124 | # XML主要部分を生成 |
125 | set ocidRootElement to doMakeRootElement() |
126 | #ボディエレメント |
127 | set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body") |
128 | #ヘッダー |
129 | set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header") |
130 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header") |
131 | ocidHeaderElement's addAttribute:(ocidAddNode) |
132 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header") |
133 | ocidHeaderElement's addAttribute:(ocidAddNode) |
134 | ocidBodyElement's addChild:(ocidHeaderElement) |
135 | #アーティクル |
136 | set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article") |
137 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article") |
138 | ocidArticleElement's addAttribute:(ocidAddNode) |
139 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article") |
140 | ocidArticleElement's addAttribute:(ocidAddNode) |
141 | ocidBodyElement's addChild:(ocidArticleElement) |
142 | #フッター |
143 | set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer") |
144 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer") |
145 | ocidFooterElement's addAttribute:(ocidAddNode) |
146 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer") |
147 | ocidFooterElement's addAttribute:(ocidAddNode) |
148 | #リンク付与(不要なら削除可) |
149 | set ocidAElement to refMe's NSXMLElement's elementWithName:("a") |
150 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/")) |
151 | (ocidAElement's addAttribute:(ocidAddNode)) |
152 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
153 | (ocidAElement's addAttribute:(ocidAddNode)) |
154 | set strContents to ("AppleScriptで生成しました") as text |
155 | (ocidAElement's setStringValue:(strContents)) |
156 | ocidFooterElement's addChild:(ocidAElement) |
157 | ocidBodyElement's addChild:(ocidFooterElement) |
158 | ############################## |
159 | # TABLE コンテンツ部分生成開始 |
160 | ############################## |
161 | #テーブル部生成開始 |
162 | set ocidTableElement to refMe's NSXMLElement's elementWithName:("table") |
163 | #【caption】 |
164 | set ocidCaptionElement to refMe's NSXMLElement's elementWithName:("caption") |
165 | ocidCaptionElement's setStringValue:("【ファイルリスト】: 行番号に※表示はCMYKデータ(PDFを除く)") |
166 | ocidTableElement's addChild:(ocidCaptionElement) |
167 | #【colgroup】 |
168 | set ocidColgroupElement to refMe's NSXMLElement's elementWithName:("colgroup") |
169 | #テーブルのタイトル部 |
170 | set listColName to {"行番号", "ファイル名", "サイズ", "Pxサイズ", "種類", "作成日", "修正日"} as list |
171 | #タイトル部の数だけ繰り返し |
172 | repeat with itemColName in listColName |
173 | #【col】col生成 |
174 | set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col")) |
175 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName)) |
176 | (ocidAddElement's addAttribute:(ocidAddNode)) |
177 | (ocidColgroupElement's addChild:(ocidAddElement)) |
178 | end repeat |
179 | #テーブルエレメントに追加 |
180 | ocidTableElement's addChild:(ocidColgroupElement) |
181 | #【thead】 |
182 | set ocidTheadElement to refMe's NSXMLElement's elementWithName:("thead") |
183 | #TR |
184 | set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr") |
185 | #タイトル部の数だけ繰り返し |
186 | repeat with itemColName in listColName |
187 | #ここはTDではなくてTHを利用 |
188 | set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th")) |
189 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName)) |
190 | (ocidAddElement's addAttribute:(ocidAddNode)) |
191 | #値を入れる |
192 | (ocidAddElement's setStringValue:(itemColName)) |
193 | #TH→TRにセット |
194 | (ocidTrElement's addChild:(ocidAddElement)) |
195 | end repeat |
196 | #TRをTHEADにセット |
197 | ocidTheadElement's addChild:(ocidTrElement) |
198 | #THEADをテーブルにセット |
199 | ocidTableElement's addChild:(ocidTheadElement) |
200 | #【tbody】 |
201 | set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody") |
202 | #行番号 |
203 | set numCntLineNo to 1 as integer |
204 | #合計ファイルサイズ用 |
205 | set numAllFileSize to 0 as integer |
206 | #ファイルのパスの数だけ繰り返し |
207 | repeat with itemFilePathURL in ocidSortedArray |
208 | ##UTIを求めて |
209 | set listResourceValue to (itemFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error| :(reference)) |
210 | set ocidContentType to (item 2 of listResourceValue) |
211 | set strUTI to (ocidContentType's identifier) as text |
212 | ######### |
213 | set strUTILIST to "public.png,public.jpeg,com.adobe.photoshop-image,public.tiff,com.apple.icns" as text |
214 | if strUTILIST contains strUTI then |
215 | log "CMYKチェック対象ファイル" |
216 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(itemFilePathURL)) |
217 | set ocidImageRepArray to ocidReadImage's representations() |
218 | set ocidImageRep to ocidImageRepArray's firstObject() |
219 | #画像サイズと解像度 |
220 | set numPxW to ocidImageRep's pixelsWide() |
221 | set numPxH to ocidImageRep's pixelsHigh() |
222 | set ocidPtSize to ocidReadImage's |size|() |
223 | set numPtW to ocidPtSize's width() |
224 | set numPtH to ocidPtSize's height() |
225 | # |
226 | #計算に必要な値 |
227 | set ocidDecPt to (refMe's NSDecimalNumber's alloc()'s initWithString:("72")) |
228 | set ocidDecIn to (refMe's NSDecimalNumber's alloc()'s initWithString:("25.4")) |
229 | # |
230 | set ocidDecWpx to (refMe's NSDecimalNumber's alloc()'s initWithString:(numPxW as text)) |
231 | set ocidDecHpx to (refMe's NSDecimalNumber's alloc()'s initWithString:(numPxH as text)) |
232 | set ocidDecWpt to (refMe's NSDecimalNumber's alloc()'s initWithString:(numPtW as text)) |
233 | set ocidDecHpt to (refMe's NSDecimalNumber's alloc()'s initWithString:(numPtH as text)) |
234 | set ocidResolutioPxW to (ocidDecWpx's decimalNumberByDividingBy:(ocidDecWpt)) |
235 | set ocidResolutinW to (ocidResolutioPxW's decimalNumberByMultiplyingBy:(ocidDecPt)) |
236 | set ocidResolutioPxH to (ocidDecHpx's decimalNumberByDividingBy:(ocidDecHpt)) |
237 | set ocidResolutinH to (ocidResolutioPxH's decimalNumberByMultiplyingBy:(ocidDecPt)) |
238 | |
239 | #小数点以下2位で四捨五入 |
240 | set appFormatter to refMe's NSNumberFormatter's alloc()'s init() |
241 | (appFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundUp)) |
242 | (appFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)) |
243 | (appFormatter's setMaximumFractionDigits:(2)) |
244 | #解像度は桁揃えしておく |
245 | set ocidResolutionW to (appFormatter's stringFromNumber:(ocidResolutinW)) |
246 | set ocidResolutionH to (appFormatter's stringFromNumber:(ocidResolutinH)) |
247 | #HTML表示用解像度 |
248 | set strSetResValueA to ((numPxW as text) & " x " & (ocidDecHpx as text) & "") as text |
249 | set strSetResValueB to ("(" & ocidResolutionW & " x " & ocidResolutionH & " ppi)") as text |
250 | ####### |
251 | set ocidColorSpace to ocidImageRep's colorSpace() |
252 | #シンプルにコンポーネント番号で判定する場合 |
253 | # 1 = GS 3=RGB 4=CMYK |
254 | set numColorCompNo to ocidColorSpace's numberOfColorComponents as integer |
255 | #colorSpaceModelで判定したい場合 |
256 | # set ocidColorModel to ocidColorSpace's colorSpaceModel() |
257 | # if ocidColorModel = (refMe's NSColorSpaceModelCMYK) then |
258 | log numColorCompNo |
259 | if numColorCompNo = 4 then |
260 | log "CMYYKデータです" |
261 | set ocidReadImage to (missing value) |
262 | set ocidImageRep to (missing value) |
263 | set boolCMYK to true as boolean |
264 | else |
265 | set boolCMYK to false as boolean |
266 | end if |
267 | else |
268 | set strSetResValueA to ("") as text |
269 | set strSetResValueB to ("") as text |
270 | set boolCMYK to false as boolean |
271 | end if |
272 | set strUTILIST to "public.movie,public.mpeg-4" as text |
273 | if strUTILIST contains strUTI then |
274 | set ocidReadAsset to (refMe's AVAsset's assetWithURL:(itemFilePathURL)) |
275 | set ocidReadAssetTrackArray to ocidReadAsset's tracks() |
276 | set ocidTrack to (ocidReadAssetTrackArray's firstObject()) |
277 | if ocidTrack = (missing value) then |
278 | set strSetResValueA to ("") as text |
279 | set strSetResValueB to ("") as text |
280 | else |
281 | set recordAssetTrackNaturalSize to ocidTrack's naturalSize() |
282 | set numTrackWidth to (width of recordAssetTrackNaturalSize) as integer |
283 | set numrackHeight to (height of recordAssetTrackNaturalSize) as integer |
284 | set strTrackWidth to (numTrackWidth) as text |
285 | set strTrackHeight to (numrackHeight) as text |
286 | set strSetResValueA to (strTrackWidth & " x " & strTrackHeight & "") as text |
287 | set strSetResValueB to ("") as text |
288 | end if |
289 | end if |
290 | |
291 | ## |
292 | #ファイルのリソースを取得 |
293 | set listResponse to (itemFilePathURL's resourceValuesForKeys:(ocidPropertieArray) |error| :(reference)) |
294 | set ocidValueDict to (item 1 of listResponse) |
295 | #TRの開始 |
296 | set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr")) |
297 | #【行番号】をTHでセット |
298 | set strZeroSupp to ("00") as text |
299 | set strZeroSupp to ("00" & numCntLineNo) as text |
300 | set strLineNO to (text -3 through -1 of strZeroSupp) as text |
301 | set ocidThElement to (refMe's NSXMLElement's elementWithName:("th")) |
302 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("行番号")) |
303 | (ocidThElement's addAttribute:(ocidAddNode)) |
304 | if boolCMYK is true then |
305 | set strSetLineNO to (strLineNO & "*") as text |
306 | else if boolCMYK is false then |
307 | set strSetLineNO to (strLineNO) as text |
308 | end if |
309 | (ocidThElement's setStringValue:(strSetLineNO)) |
310 | (ocidTrElement's addChild:(ocidThElement)) |
311 | #【ファイル名】をTDでセット |
312 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLNameKey)) |
313 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
314 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("ファイル名")) |
315 | (ocidTdElement's addAttribute:(ocidAddNode)) |
316 | #### |
317 | set itemFilePath to itemFilePathURL's |path| |
318 | set ocidRange to (itemFilePath's rangeOfString:(ocidDirPath)) |
319 | set numLength to (|length| of ocidRange) + 1 as integer |
320 | set ocidRlativePath to (itemFilePath's substringFromIndex:(numLength)) |
321 | |
322 | #↑のTDの内容=ファイル名にリンクを付与 |
323 | set ocidAElement to (refMe's NSXMLElement's elementWithName:("a")) |
324 | set strHref to ("./" & ocidRlativePath) as text |
325 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strHref)) |
326 | (ocidAElement's addAttribute:(ocidAddNode)) |
327 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
328 | (ocidAElement's addAttribute:(ocidAddNode)) |
329 | set strHref to (ocidRlativePath) as text |
330 | (ocidAElement's setStringValue:(strHref)) |
331 | #リンクをTDにセット |
332 | (ocidTdElement's addChild:(ocidAElement)) |
333 | #TDをTRにセット |
334 | (ocidTrElement's addChild:(ocidTdElement)) |
335 | #【ファイルサイズ】TD |
336 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLFileSizeKey)) |
337 | #ファイルサイズの合計に加算 |
338 | set strValue to ocidValue as text |
339 | set numValue to strValue as integer |
340 | set numAllFileSize to (numAllFileSize + numValue) |
341 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
342 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("ファイルサイズ")) |
343 | (ocidTdElement's addAttribute:(ocidAddNode)) |
344 | #単位による分岐 |
345 | set numValue to ocidValue's intValue() as number |
346 | set numFileSize to numValue as integer |
347 | # |
348 | set numByteUnits to 1000 as integer |
349 | # バイト単位 10.5以前やWindowsターゲットの場合は1024に |
350 | |
351 | if (numFileSize) < numByteUnits then |
352 | log "b:バイト単位" |
353 | set strFileSize to doRound2Dec(numFileSize) |
354 | set strValue to (strFileSize & " b") as text |
355 | else if numFileSize < (numByteUnits * numByteUnits) then |
356 | log "kb:キロバイト単位" |
357 | set strFileSize to doRound2Dec(numFileSize / numByteUnits) |
358 | set strValue to (strFileSize & "kb") as text |
359 | else if numFileSize < (numByteUnits * numByteUnits * numByteUnits) then |
360 | log "mb:メガバイト単位" |
361 | set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits)) |
362 | set strValue to (strFileSize & " mb") as text |
363 | else |
364 | log "gb:ギガバイト単位" |
365 | set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits * numByteUnits)) |
366 | set strValue to (strFileSize & " gb") as text |
367 | end if |
368 | (ocidTdElement's setStringValue:(strValue)) |
369 | (ocidTrElement's addChild:(ocidTdElement)) |
370 | #【種類】TDでセット |
371 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLContentTypeKey))'s localizedDescription() |
372 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
373 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("解像度")) |
374 | (ocidTdElement's addAttribute:(ocidAddNode)) |
375 | # set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("kind_string")) |
376 | # (ocidTdElement's addAttribute:(ocidAddNode)) |
377 | # |
378 | set ocidPElement to (refMe's NSXMLElement's elementWithName:("p")) |
379 | (ocidPElement's setStringValue:(strSetResValueA)) |
380 | set ocidSmallElement to (refMe's NSXMLElement's elementWithName:("small")) |
381 | (ocidSmallElement's setStringValue:(strSetResValueB)) |
382 | (ocidTdElement's addChild:(ocidPElement)) |
383 | (ocidTdElement's addChild:(ocidSmallElement)) |
384 | |
385 | (ocidTrElement's addChild:(ocidTdElement)) |
386 | |
387 | |
388 | |
389 | #【種類】TDでセット |
390 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLContentTypeKey))'s localizedDescription() |
391 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
392 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("種類")) |
393 | (ocidTdElement's addAttribute:(ocidAddNode)) |
394 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("kind_string")) |
395 | (ocidTdElement's addAttribute:(ocidAddNode)) |
396 | (ocidTdElement's setStringValue:(ocidValue)) |
397 | (ocidTrElement's addChild:(ocidTdElement)) |
398 | #【作成日】TDでセット |
399 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLCreationDateKey)) |
400 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
401 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("作成")) |
402 | (ocidTdElement's addAttribute:(ocidAddNode)) |
403 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("date_string")) |
404 | (ocidTdElement's addAttribute:(ocidAddNode)) |
405 | set strDate to (ocidValue as date) as text |
406 | (ocidTdElement's setStringValue:(strDate)) |
407 | (ocidTrElement's addChild:(ocidTdElement)) |
408 | #【修正日】TDでセット |
409 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLContentModificationDateKey)) |
410 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
411 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("修正日")) |
412 | (ocidTdElement's addAttribute:(ocidAddNode)) |
413 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("date_string")) |
414 | (ocidTdElement's addAttribute:(ocidAddNode)) |
415 | set strDate to (ocidValue as date) as text |
416 | (ocidTdElement's setStringValue:(strDate)) |
417 | (ocidTrElement's addChild:(ocidTdElement)) |
418 | #出来上がったTRをTBODYにセット |
419 | (ocidTbodyElement's addChild:(ocidTrElement)) |
420 | #項目番号のカウントアップ |
421 | set numCntLineNo to (numCntLineNo + 1) as integer |
422 | end repeat |
423 | #TBODYをテーブルにセット |
424 | ocidTableElement's addChild:(ocidTbodyElement) |
425 | #【tfoot】 TRで |
426 | set ocidTfootElement to refMe's NSXMLElement's elementWithName:("tfoot") |
427 | set ocidTrElement to refMe's NSXMLElement's elementWithName:("tr") |
428 | #項目数を取得して |
429 | set numCntCol to (count of listColName) as integer |
430 | #colspan指定して1行でセット |
431 | set ocidThElement to (refMe's NSXMLElement's elementWithName:("th")) |
432 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり")) |
433 | (ocidThElement's addAttribute:(ocidAddNode)) |
434 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text)) |
435 | (ocidThElement's addAttribute:(ocidAddNode)) |
436 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row")) |
437 | (ocidThElement's addAttribute:(ocidAddNode)) |
438 | # |
439 | set numByteUnits to 1000 as integer |
440 | # バイト単位 10.5以前やWindowsターゲットの場合は1024に |
441 | if numAllFileSize < numByteUnits then |
442 | log "b:バイト単位" |
443 | set strFileSize to doRound2Dec(numAllFileSize) |
444 | set strValue to "フォルダ合計:" & strFileSize & " b" as text |
445 | |
446 | else if numAllFileSize < (numByteUnits * numByteUnits) then |
447 | log "kb:キロバイト単位" |
448 | set strFileSize to doRound2Dec(numAllFileSize / numByteUnits) |
449 | set strValue to "フォルダ合計:" & strFileSize & " kb" as text |
450 | |
451 | else if numAllFileSize < (numByteUnits * numByteUnits * numByteUnits) then |
452 | log "mb:メガバイト単位" |
453 | set strFileSize to doRound2Dec(numAllFileSize / (numByteUnits * numByteUnits)) |
454 | set strValue to "フォルダ合計:" & strFileSize & " mb" as text |
455 | else |
456 | log "gb:ギガバイト単位" |
457 | set strFileSize to doRound2Dec(numAllFileSize / (numByteUnits * numByteUnits * numByteUnits)) |
458 | set strValue to "フォルダ合計:" & strFileSize & " gb" as text |
459 | end if |
460 | |
461 | |
462 | |
463 | if (numAllFileSize) < 102400 then |
464 | set numValue to (numAllFileSize / 1024) as integer |
465 | set strValue to "フォルダ合計:" & numValue & " kb" as text |
466 | else if (numAllFileSize) > (10240 * 100000) then |
467 | set numValue to (numAllFileSize / (10240 * 100000)) |
468 | set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init() |
469 | (ocidFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)) |
470 | (ocidFormatter's setMinimumFractionDigits:(2)) |
471 | (ocidFormatter's setMaximumFractionDigits:(2)) |
472 | set strValue to (ocidFormatter's stringFromNumber:(numValue)) as text |
473 | set strValue to "フォルダ合計:" & strValue & " gb" as text |
474 | else |
475 | set numValue to (numAllFileSize / 1024000) as integer |
476 | set strValue to "フォルダ合計:" & numValue & " mb" as text |
477 | end if |
478 | ocidThElement's setStringValue:(strValue) |
479 | |
480 | #THをTRにセットして |
481 | ocidTrElement's addChild:(ocidThElement) |
482 | #TRをTFOOTにセット |
483 | ocidTfootElement's addChild:(ocidTrElement) |
484 | #TFOOTをテーブルにセット |
485 | ocidTableElement's addChild:(ocidTfootElement) |
486 | # 出来上がったテーブルをArticleエレメントにセット |
487 | ocidArticleElement's addChild:(ocidTableElement) |
488 | # |
489 | ocidRootElement's addChild:(ocidBodyElement) |
490 | ############################## |
491 | # TABLE |
492 | ############################## |
493 | #ROOTエレメントをXMLにセット |
494 | ocidXMLDoc's setRootElement:(ocidRootElement) |
495 | #読み取りやすい表示 |
496 | set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint) |
497 | #保存 |
498 | set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference) |
499 | set ocidSaveFilePath to ocidSaveFilePathURL's |path| |
500 | set ocidContainerDirPathURL to ocidSaveFilePathURL's URLByDeletingLastPathComponent() |
501 | set ocidContainerDirPath to ocidContainerDirPathURL's |path| |
502 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
503 | set boolDone to appSharedWorkspace's selectFile:(ocidSaveFilePath) inFileViewerRootedAtPath:(ocidContainerDirPath) |
504 | set boolDone to appSharedWorkspace's openURL:(ocidSaveFilePathURL) |
505 | if (boolDone as boolean) is false then |
506 | #ファイルを開く |
507 | set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias |
508 | tell application "Finder" |
509 | open file aliasSaveFilePath |
510 | end tell |
511 | end if |
512 | ##処理終了 |
513 | return "処理終了" |
514 | end open |
515 | |
516 | ############################## |
517 | # 小数点以下2桁処理 |
518 | ############################## |
519 | |
520 | to doRound2Dec(argNumber) |
521 | set strDecNo to ((round (argNumber * 100)) / 100) as text |
522 | return strDecNo |
523 | end doRound2Dec |
524 | ############################## |
525 | # 基本的なHTMLの構造 |
526 | ############################## |
527 | to doMakeRootElement() |
528 | # |
529 | set ocidRootElement to refMe's NSXMLElement's elementWithName:("html") |
530 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja") |
531 | ocidRootElement's addAttribute:(ocidAddNode) |
532 | # |
533 | set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head") |
534 | # |
535 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("title") |
536 | ocidAddElement's setStringValue:("ファイル一覧") |
537 | ocidHeadElement's addChild:(ocidAddElement) |
538 | # http-equiv |
539 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
540 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type") |
541 | ocidAddElement's addAttribute:(ocidAddNode) |
542 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8") |
543 | ocidAddElement's addAttribute:(ocidAddNode) |
544 | ocidHeadElement's addChild:(ocidAddElement) |
545 | # |
546 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
547 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type") |
548 | ocidAddElement's addAttribute:(ocidAddNode) |
549 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css") |
550 | ocidAddElement's addAttribute:(ocidAddNode) |
551 | ocidHeadElement's addChild:(ocidAddElement) |
552 | # |
553 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
554 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type") |
555 | ocidAddElement's addAttribute:(ocidAddNode) |
556 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript") |
557 | ocidAddElement's addAttribute:(ocidAddNode) |
558 | ocidHeadElement's addChild:(ocidAddElement) |
559 | # |
560 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
561 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport") |
562 | ocidAddElement's addAttribute:(ocidAddNode) |
563 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720") |
564 | ocidAddElement's addAttribute:(ocidAddNode) |
565 | ocidHeadElement's addChild:(ocidAddElement) |
566 | # |
567 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("style") |
568 | 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 } }") |
569 | ocidHeadElement's addChild:(ocidAddElement) |
570 | # |
571 | ocidRootElement's addChild:(ocidHeadElement) |
572 | # |
573 | return ocidRootElement |
574 | end doMakeRootElement |
AppleScriptで生成しました |
| 固定リンク