Diff

2つのフォルダの内容を比較してHTML出力する

出力結果はこんな感じ 202410310337031_2182x1060
AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003# com.cocolog-nifty.quicktimer.icefloe
004#  2つのフォルダで比較します
005#  フォルダを2箇所選択してください
006# 出力はHTMLをテンポラリー(再起動時に自動で削除されます)に保存
007#
008# 初回作成 v1 20241031 まだあまりテストもしていないのでアレだけど
009----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
010use AppleScript version "2.8"
011use framework "Foundation"
012use framework "AppKit"
013use framework "UniformTypeIdentifiers"
014use scripting additions
015
016property refMe : a reference to current application
017
018
019################
020#パス フォルダの選択
021set strMes to ("フォルダを選んでください 主フォルダ") as text
022set aliasDirPathA to (choose folder strMes with prompt strMes with invisibles and showing package contents without multiple selections allowed) as alias
023set strDirPathA to (POSIX path of aliasDirPathA) as text
024set ocidDirPathAStr to refMe's NSString's stringWithString:(strDirPathA)
025set ocidDirPathA to ocidDirPathAStr's stringByStandardizingPath()
026set ocidDirPathAURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPathA) isDirectory:true)
027set ocidDirNameA to ocidDirPathAURL's lastPathComponent()
028set ocidDirAbsPathA to ocidDirPathAURL's absoluteString()
029
030set strMes to ("フォルダを選んでください 比較先フォルダ") as text
031set aliasDirPathB to (choose folder strMes with prompt strMes with invisibles and showing package contents without multiple selections allowed) as alias
032set strDirPathB to (POSIX path of aliasDirPathB) as text
033set ocidDirPathBStr to refMe's NSString's stringWithString:(strDirPathB)
034set ocidDirPathB to ocidDirPathBStr's stringByStandardizingPath()
035set ocidDirPathBURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPathB) isDirectory:true)
036set ocidDirNameB to ocidDirPathBURL's lastPathComponent()
037set ocidDirAbsPathB to ocidDirPathBURL's absoluteString()
038
039################
040#コンテンツの収集
041set appFileManager to refMe's NSFileManager's defaultManager()
042set ocidPropertiesArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
043ocidPropertiesArray's addObject:(refMe's NSURLIsDirectoryKey)
044ocidPropertiesArray's addObject:(refMe's NSURLIsRegularFileKey)
045ocidPropertiesArray's addObject:(refMe's NSURLNameKey)
046ocidPropertiesArray's addObject:(refMe's NSURLPathKey)
047ocidPropertiesArray's addObject:(refMe's NSURLFileContentIdentifierKey)
048ocidPropertiesArray's addObject:(refMe's NSURLFileSizeKey)
049ocidPropertiesArray's addObject:(refMe's NSURLContentModificationDateKey)
050ocidPropertiesArray's addObject:(refMe's NSURLCreationDateKey)
051set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
052#主フォルダ A
053set ocidEmuDictA to appFileManager's enumeratorAtURL:(ocidDirPathAURL) includingPropertiesForKeys:(ocidPropertiesArray) options:(ocidOption) errorHandler:(reference)
054#比較フォルダ B
055set ocidEmuDictB to appFileManager's enumeratorAtURL:(ocidDirPathBURL) includingPropertiesForKeys:(ocidPropertiesArray) options:(ocidOption) errorHandler:(reference)
056log "URLの収集"
057
058################
059# A のURLDICT作成
060set ocidEmuFileURLArrayA to ocidEmuDictA's allObjects()
061set ocidDirurlDictA to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
062
063repeat with itemURL in ocidEmuFileURLArrayA
064  #判定して(このケースはディレクトリなら)
065  set listResponse to (itemURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error| :(reference))
066  # listResponseは{boolean,VALUE,NSERROR}のリスト形式
067  if (item 1 of listResponse) is (true) then
068    set boolIsDir to (item 2 of listResponse) as boolean
069    if boolIsDir is false then
070      #出力用のDICTに追加していく
071      set ocidItemFilePath to itemURL's |path|()
072      set ocidRootPath to (ocidItemFilePath's stringByReplacingOccurrencesOfString:(ocidDirPathA) withString:(""))
073      (ocidDirurlDictA's setObject:(itemURL) forKey:(ocidRootPath))
074    end if
075  else if (item 1 of listResponse) is (false) then
076    log (item 3 of listResponse)'s code() as text
077    log (item 3 of listResponse)'s localizedDescription() as text
078  end if
079end repeat
080
081log "A先に選んだフォルダのコンテンツ"
082################
083# B のURLDICT作成
084set ocidEmuFileURLArrayB to ocidEmuDictB's allObjects()
085set ocidDirurlDictB to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
086
087repeat with itemURL in ocidEmuFileURLArrayB
088  #判定して(このケースはディレクトリなら)
089  set listResponse to (itemURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error| :(reference))
090  # listResponseは{boolean,VALUE,NSERROR}のリスト形式
091  if (item 1 of listResponse) is (true) then
092    set boolIsDir to (item 2 of listResponse) as boolean
093    if boolIsDir is false then
094      #出力用のDICTに追加していく
095      set ocidItemFilePath to itemURL's |path|()
096      set ocidRootPath to (ocidItemFilePath's stringByReplacingOccurrencesOfString:(ocidDirPathB) withString:(""))
097      (ocidDirurlDictB's setObject:(itemURL) forKey:(ocidRootPath))
098    end if
099  else if (item 1 of listResponse) is (false) then
100    log (item 3 of listResponse)'s code() as text
101    log (item 3 of listResponse)'s localizedDescription() as text
102  end if
103end repeat
104
105log "B後に選んだフォルダのコンテンツ"
106################
107# Aを基軸にBにあるか判定
108#AllKey取り出して
109set ocidAllKeysA to ocidDirurlDictA's allKeys()
110#ソート
111set ocidSortedKeyA to ocidAllKeysA's sortedArrayUsingSelector:("localizedStandardCompare:")
112
113#出力用のDICT
114set ocidDictAB to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
115set ocidDictAX to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
116
117repeat with itemKeyA in ocidAllKeysA
118  set ocidItemURLA to (ocidDirurlDictA's objectForKey:(itemKeyA))
119  set ocidValueB to (ocidDirurlDictB's objectForKey:(itemKeyA))
120  if ocidValueB = (missing value) then
121    #AにあるBにない場合
122    set listSetValue to {ocidItemURLA, (missing value)} as list
123    (ocidDictAX's setObject:(listSetValue) forKey:(itemKeyA))
124  else
125    #両方ある場合
126    set listSetValue to {ocidItemURLA, ocidValueB} as list
127    (ocidDictAB's setObject:(listSetValue) forKey:(itemKeyA))
128  end if
129  
130end repeat
131log "AB存在判定A"
132
133################
134# Bを基軸にAにあるか判定
135#AllKey取り出して
136set ocidAllKeysB to ocidDirurlDictB's allKeys()
137#ソート
138set ocidSortedKeyB to ocidAllKeysB's sortedArrayUsingSelector:("localizedStandardCompare:")
139#出力用のDICT
140set ocidDictXB to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
141#
142repeat with itemKeyB in ocidSortedKeyB
143  set ocidItemURLB to (ocidDirurlDictB's objectForKey:(itemKeyB))
144  set ocidValueA to (ocidDirurlDictA's objectForKey:(itemKeyB))
145  if ocidValueA = (missing value) then
146    #Aに無い Bにある場合
147    set listSetValue to {(missing value), ocidItemURLB} as list
148    (ocidDictXB's setObject:(listSetValue) forKey:(itemKeyB))
149  end if
150  
151end repeat
152log "AB存在判定B"
153
154################
155# ocidDictAB 両方にある
156# ocidDictAX  AにあってBにない
157# ocidDictXB  BにあってAにない
158#   ocidDictALL 全部入り
159set ocidDictALL to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
160ocidDictALL's addEntriesFromDictionary:(ocidDictAB)
161ocidDictALL's addEntriesFromDictionary:(ocidDictAX)
162ocidDictALL's addEntriesFromDictionary:(ocidDictXB)
163set ocidAllKeys to ocidDictALL's allKeys()
164set ocidSortedAllKey to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
165
166log "DICT生成終了"
167##############
168set ocidOutPutDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
169#
170repeat with itemKye in ocidSortedAllKey
171  set ItemArray to (ocidDictALL's objectForKey:(itemKye))
172  #######
173  #AのURLは?
174  set ocidItemA to ItemArray's firstObject()
175  #BのURLは?
176  set ocidItemB to ItemArray's lastObject()
177  ########
178  #判定開始
179  if ocidItemA = (refMe's NSNull's |null|) then
180    ########
181    #BにあってAにない
182    set listValueA to {(missing value), (missing value), (missing value), (missing value), (missing value)} as list
183    #修正日
184    set ocidFileNameB to ocidItemB's lastPathComponent()
185    set strAbsoluteStringB to ocidItemB's absoluteString() as text
186    #
187    set listResponse to (ocidItemB's getResourceValue:(reference) forKey:(refMe's NSURLContentModificationDateKey) |error| :(reference))
188    set ocidModDay to (item 2 of listResponse)
189    #ファイルサイズ
190    set listResponse to (ocidItemB's getResourceValue:(reference) forKey:(refMe's NSURLFileSizeKey) |error| :(reference))
191    set ocidFileSize to (item 2 of listResponse)
192    set listValueB to {(ocidFileNameB), (strAbsoluteStringB), (ocidItemB), (ocidFileSize), (ocidModDay)} as list
193  else
194    ########
195    #AにURLがある場合
196    #####
197    set ocidFileNameA to ocidItemA's lastPathComponent()
198    set strAbsoluteStringA to ocidItemA's absoluteString() as text
199    #修正日
200    set listResponse to (ocidItemA's getResourceValue:(reference) forKey:(refMe's NSURLContentModificationDateKey) |error| :(reference))
201    set ocidModDay to (item 2 of listResponse)
202    #ファイルサイズ
203    set listResponse to (ocidItemA's getResourceValue:(reference) forKey:(refMe's NSURLFileSizeKey) |error| :(reference))
204    set ocidFileSize to (item 2 of listResponse)
205    set listValueA to {(ocidFileNameA), (strAbsoluteStringA), (ocidItemA), (ocidFileSize), (ocidModDay)} as list
206    #####
207    #AにあってBにない  
208    if ocidItemB = (refMe's NSNull's |null|) then
209      set listValueB to {(missing value), (missing value), (missing value), (missing value), (missing value)} as list
210    else
211      ########
212      #AB両方ある
213      #####
214      set ocidFileNameB to ocidItemB's lastPathComponent()
215      set strAbsoluteStringB to ocidItemB's absoluteString() as text
216      #修正日
217      set listResponse to (ocidItemB's getResourceValue:(reference) forKey:(refMe's NSURLContentModificationDateKey) |error| :(reference))
218      set ocidModDay to (item 2 of listResponse)
219      #ファイルサイズ
220      set listResponse to (ocidItemB's getResourceValue:(reference) forKey:(refMe's NSURLFileSizeKey) |error| :(reference))
221      set ocidFileSize to (item 2 of listResponse)
222      set listValueB to {(ocidFileNameB), (strAbsoluteStringB), (ocidItemB), (ocidFileSize), (ocidModDay)} as list
223    end if
224  end if
225  set listSetValue to {listValueA, listValueB} as list
226  (ocidOutPutDict's setObject:(listSetValue) forKey:(itemKye))
227end repeat
228
229log "AB判定済みリソース入りDICT生成完了"
230####################
231#保存先確保
232set ocidTempDirURL to appFileManager's temporaryDirectory()
233set ocidUUID to refMe's NSUUID's alloc()'s init()
234set ocidUUIDString to ocidUUID's UUIDString
235set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
236set appFileManager to refMe's NSFileManager's defaultManager()
237set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0
238ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
239set listBoolMakeDir to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference)
240set strFileName to "Folder_Diff.html" as text
241set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strFileName) isDirectory:false
242
243log "保存先確保"
244
245##############################
246# XML 生成開始
247##############################
248set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init()
249(ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind))
250# DTD付与
251set ocidDTD to refMe's NSXMLDTD's alloc()'s init()
252(ocidDTD's setName:("html"))
253(ocidXMLDoc's setDTD:(ocidDTD))
254# XML主要部分を生成
255set ocidRootElement to doMakeRootElement()
256#ボディエレメント
257set ocidBodyElement to (refMe's NSXMLElement's elementWithName:("body"))
258#ヘッダー
259set ocidHeaderElement to (refMe's NSXMLElement's elementWithName:("header"))
260set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("header"))
261(ocidHeaderElement's addAttribute:(ocidAddNode))
262set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header"))
263(ocidHeaderElement's addAttribute:(ocidAddNode))
264(ocidBodyElement's addChild:(ocidHeaderElement))
265#アーティクル
266set ocidArticleElement to (refMe's NSXMLElement's elementWithName:("article"))
267set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("article"))
268(ocidArticleElement's addAttribute:(ocidAddNode))
269set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article"))
270(ocidArticleElement's addAttribute:(ocidAddNode))
271(ocidBodyElement's addChild:(ocidArticleElement))
272#フッター
273set ocidFooterElement to (refMe's NSXMLElement's elementWithName:("footer"))
274set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer"))
275(ocidFooterElement's addAttribute:(ocidAddNode))
276set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer"))
277(ocidFooterElement's addAttribute:(ocidAddNode))
278#リンク付与(不要なら削除可)
279set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
280set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/"))
281(ocidAElement's addAttribute:(ocidAddNode))
282set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank"))
283(ocidAElement's addAttribute:(ocidAddNode))
284set strContents to ("AppleScriptで生成しました") as text
285(ocidAElement's setStringValue:(strContents))
286(ocidFooterElement's addChild:(ocidAElement))
287(ocidBodyElement's addChild:(ocidFooterElement))
288
289log "HTMLヘッダー部終了"
290
291##############################
292# TABLE コンテンツ部分生成開始
293##############################
294############
295#【table】
296set ocidTableElement to (refMe's NSXMLElement's elementWithName:("table"))
297set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("summary") stringValue:("フォルダの内容を比較したHTMLテーブルです"))
298(ocidTableElement's addAttribute:(ocidAddNode))
299
300############
301#【caption】
302set ocidCaptionElement to (refMe's NSXMLElement's elementWithName:("caption"))
303(ocidCaptionElement's setStringValue:("【ファイルリスト】: フォルダ内容比較"))
304(ocidTableElement's addChild:(ocidCaptionElement))
305
306############
307#【colgroup】
308set ocidColgroupElement to (refMe's NSXMLElement's elementWithName:("colgroup"))
309#テーブルのタイトル部
310set listColName to {"行番号", "ファイル名", "パス", "サイズ", "修正日", "Size", "更新", "パス", "サイズ", "修正日"} as list
311set listColID to {"liineNO", "FileName", "FilePath", "FileSize", "ModDay", "Size", "Mode", "FilePath", "FileSize", "ModDay"} as list
312#項目数を取得して
313set numCntCol to (count of listColName) as integer
314#タイトル部の数だけ繰り返し
315repeat with itemNo from 1 to numCntCol by 1
316  set strItemName to (item itemNo of listColName) as text
317  #【col】col生成
318  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col"))
319  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strItemName))
320  (ocidAddElement's addAttribute:(ocidAddNode))
321  (ocidColgroupElement's addChild:(ocidAddElement))
322end repeat
323#テーブルエレメントに追加
324(ocidTableElement's addChild:(ocidColgroupElement))
325
326log "COL部終了"
327
328############
329#【thead】
330set ocidTheadElement to (refMe's NSXMLElement's elementWithName:("thead"))
331######
332#TR フォルダ名 
333set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
334set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
335set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:("2"))
336(ocidThElement's addAttribute:(ocidAddNode))
337(ocidThElement's setStringValue:(""))
338(ocidTrElement's addChild:(ocidThElement))
339set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
340set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:("3"))
341(ocidThElement's addAttribute:(ocidAddNode))
342set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-align: center;"))
343(ocidThElement's addAttribute:(ocidAddNode))
344#リンク
345set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
346set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("File Link"))
347(ocidAElement's addAttribute:(ocidAddNode))
348set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(ocidDirAbsPathA))
349(ocidAElement's addAttribute:(ocidAddNode))
350set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-decoration: none;"))
351(ocidAElement's addAttribute:(ocidAddNode))
352(ocidAElement's setStringValue:(ocidDirNameA))
353#リンクをTHにセット
354(ocidThElement's addChild:(ocidAElement))
355#比較部
356(ocidTrElement's addChild:(ocidThElement))
357set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
358set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:("2"))
359(ocidThElement's addAttribute:(ocidAddNode))
360(ocidThElement's setStringValue:(""))
361(ocidTrElement's addChild:(ocidThElement))
362#フォルダB
363set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
364set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:("3"))
365(ocidThElement's addAttribute:(ocidAddNode))
366set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-align: center;"))
367(ocidThElement's addAttribute:(ocidAddNode))
368#リンク
369set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
370set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("File Link"))
371(ocidAElement's addAttribute:(ocidAddNode))
372set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(ocidDirAbsPathB))
373(ocidAElement's addAttribute:(ocidAddNode))
374set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-decoration: none;"))
375(ocidAElement's addAttribute:(ocidAddNode))
376(ocidAElement's setStringValue:(ocidDirNameB))
377#リンクをTHにセット
378(ocidThElement's addChild:(ocidAElement))
379#THをTRにセット
380(ocidTrElement's addChild:(ocidThElement))
381#TRをTHEADに入れる
382(ocidTheadElement's addChild:(ocidTrElement))
383#######
384#TR 分類 
385set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
386#タイトル部の数だけ繰り返し
387repeat with itemNo from 1 to numCntCol by 1
388  set strItemName to (item itemNo of listColName) as text
389  set strItemID to (item itemNo of listColID) as text
390  #ここはTDではなくてTHを利用
391  set ocidAddElement to (refMe's NSXMLElement's elementWithName:("td"))
392  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strItemName))
393  (ocidAddElement's addAttribute:(ocidAddNode))
394  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:(strItemID))
395  (ocidAddElement's addAttribute:(ocidAddNode))
396  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("col"))
397  (ocidAddElement's addAttribute:(ocidAddNode))
398  #値を入れる
399  (ocidAddElement's setStringValue:(strItemName))
400  #TH→TRにセット
401  (ocidTrElement's addChild:(ocidAddElement))
402end repeat
403#TRをTHEADにセット
404(ocidTheadElement's addChild:(ocidTrElement))
405#THEADをテーブルにセット
406(ocidTableElement's addChild:(ocidTheadElement))
407
408log "THEAD部終了"
409
410############
411#【tbody】
412set ocidTbodyElement to refMe's NSXMLElement's elementWithName:("tbody")
413#キーを取り出してソートしておく
414set ocidAllKeys to ocidOutPutDict's allKeys()
415set ocidSortedAllKey to ocidAllKeys's sortedArrayUsingSelector:("localizedStandardCompare:")
416#日付フォーマット
417set appDateFormatter to refMe's NSDateFormatter's alloc()'s init()
418(appDateFormatter's setDateFormat:("yyyyMMdd"))
419log "TBODY処理開始"
420############
421set numCntLineNo to 1 as integer
422#ファイルサイズの基準
423set numByteUnits to 1000 as integer
424#処理する総回数
425# バイト単位 10.5以前やWindowsターゲットの場合は1024に
426set numCntAllKey to ocidSortedAllKey's |count|() as integer
427#DICTの数だけくりかえし
428repeat with itemKey in ocidSortedAllKey
429  set ocidItemArray to (ocidOutPutDict's objectForKey:(itemKey))
430  #ファイル名 パス サイズ 修正日
431  set ocidArrayA to ocidItemArray's firstObject()
432  set ocidNameA to (ocidArrayA's objectAtIndex:(0))
433  set ocidPathA to (ocidArrayA's objectAtIndex:(1))
434  set ocidUrlA to (ocidArrayA's objectAtIndex:(2))
435  set ocidSizeA to (ocidArrayA's objectAtIndex:(3))
436  set ocidModA to (ocidArrayA's objectAtIndex:(4))
437  set ocidModDateAStr to (appDateFormatter's stringFromDate:(ocidModA))
438  # 修正日はこの時点でフォーマット済み
439  set ocidArrayB to ocidItemArray's lastObject()
440  set ocidNameB to (ocidArrayB's objectAtIndex:(0))
441  set ocidPathB to (ocidArrayB's objectAtIndex:(1))
442  set ocidUrlB to (ocidArrayB's objectAtIndex:(2))
443  set ocidSizeB to (ocidArrayB's objectAtIndex:(3))
444  set ocidModB to (ocidArrayB's objectAtIndex:(4))
445  set ocidModDateBStr to (appDateFormatter's stringFromDate:(ocidModB))
446  #COL のID Name用
447  set strColName1 to (item 1 of listColName) as text
448  set strColName2 to (item 2 of listColName) as text
449  set strColName3 to (item 3 of listColName) as text
450  set strColName4 to (item 4 of listColName) as text
451  set strColName5 to (item 5 of listColName) as text
452  set strColName6 to (item 6 of listColName) as text
453  set strColName7 to (item 7 of listColName) as text
454  set strColName8 to (item 8 of listColName) as text
455  set strColName9 to (item 9 of listColName) as text
456  set strColName10 to (item 10 of listColName) as text
457  #COLの headers用
458  set strItemID1 to (item 1 of listColID) as text
459  set strItemID2 to (item 2 of listColID) as text
460  set strItemID3 to (item 3 of listColID) as text
461  set strItemID4 to (item 4 of listColID) as text
462  set strItemID5 to (item 5 of listColID) as text
463  set strItemID6 to (item 6 of listColID) as text
464  set strItemID7 to (item 7 of listColID) as text
465  set strItemID8 to (item 8 of listColID) as text
466  set strItemID9 to (item 9 of listColID) as text
467  set strItemID10 to (item 10 of listColID) as text
468  #
469  log "値取得OK"
470  
471  ################################
472  #キーがパスなのでファイル名を取得
473  set ocidLastPath to itemKey's lastPathComponent()
474  
475  ########
476  #【TR】の開始
477  set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
478  #【行番号】をTHでセット
479  set strZeroSupp to ("00") as text
480  set strZeroSupp to ("00" & numCntLineNo) as text
481  set strLineNO to (text -3 through -1 of strZeroSupp) as text
482  set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
483  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName1))
484  (ocidThElement's addAttribute:(ocidAddNode))
485  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
486  (ocidThElement's addAttribute:(ocidAddNode))
487  set strSetValue to ("LineNO" & strLineNO) as text
488  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:(strSetValue))
489  (ocidThElement's addAttribute:(ocidAddNode))
490  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strItemID1))
491  (ocidThElement's addAttribute:(ocidAddNode))
492  (ocidThElement's setStringValue:(strLineNO))
493  (ocidTrElement's addChild:(ocidThElement))
494  
495  
496  ############################
497  # 先に選んだフォルダA
498  ########
499  #【ファイル名】をTDでセット
500  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
501  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName2))
502  (ocidTdElement's addAttribute:(ocidAddNode))
503  set strSetValue to (strFileName & " " & strItemID2) as text
504  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
505  (ocidTdElement's addAttribute:(ocidAddNode))
506  #テキストの値としてファイル名を入れて
507  (ocidTdElement's setStringValue:(ocidLastPath))
508  #TDをTRにセット
509  (ocidTrElement's addChild:(ocidTdElement))
510  
511  ########
512  #【パス】
513  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
514  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName3))
515  (ocidTdElement's addAttribute:(ocidAddNode))
516  set strSetValue to (strFileName & " " & strItemID3) as text
517  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
518  (ocidTdElement's addAttribute:(ocidAddNode))
519  #
520  if ocidUrlA is not (refMe's NSNull's |null|()) then
521    set ocidLabelElement to (refMe's NSXMLElement's elementWithName:("label"))
522    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("for") stringValue:("FilePath"))
523    (ocidLabelElement's addAttribute:(ocidAddNode))
524    #
525    set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
526    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("File Link"))
527    (ocidAElement's addAttribute:(ocidAddNode))
528    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(ocidPathA))
529    (ocidAElement's addAttribute:(ocidAddNode))
530    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-decoration: none;"))
531    (ocidAElement's addAttribute:(ocidAddNode))
532    (ocidAElement's setStringValue:("●"))
533    #リンクをTDにセット
534    (ocidLabelElement's addChild:(ocidAElement))
535    #TDをTRにセット
536    (ocidTdElement's addChild:(ocidLabelElement))
537    #
538    set ocidInputElement to (refMe's NSXMLElement's elementWithName:("input"))
539    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("type") stringValue:("text"))
540    (ocidInputElement's addAttribute:(ocidAddNode))
541    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("FilePath"))
542    (ocidInputElement's addAttribute:(ocidAddNode))
543    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("name") stringValue:("FilePath"))
544    (ocidInputElement's addAttribute:(ocidAddNode))
545    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("border: none; width: 72px;"))
546    (ocidInputElement's addAttribute:(ocidAddNode))
547    set strSetValue to ocidUrlA's |path| as text
548    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("value") stringValue:(strSetValue))
549    (ocidInputElement's addAttribute:(ocidAddNode))
550    #INPUTをTDにセット
551    (ocidTdElement's addChild:(ocidInputElement))
552  end if
553  #TDをTRにセット
554  (ocidTrElement's addChild:(ocidTdElement))
555  ########
556  #サイズ
557  ############
558  #【ファイルサイズ】TD
559  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
560  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName4))
561  (ocidTdElement's addAttribute:(ocidAddNode))
562  set strSetValue to (strFileName & " " & strItemID4) as text
563  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
564  (ocidTdElement's addAttribute:(ocidAddNode))
565  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-align: right;"))
566  (ocidTdElement's addAttribute:(ocidAddNode))
567  #単位による分岐
568  if ocidSizeA is (refMe's NSNull's |null|()) then
569    set strValue to ("") as text
570  else
571    set strValue to ocidSizeA as text
572    set numFileSize to strValue as integer
573    if (numFileSize) < numByteUnits then
574      set strFileSize to doRound2Dec(numFileSize)
575      set strValue to (strFileSize & " b") as text
576    else if numFileSize < (numByteUnits * numByteUnits) then
577      set strFileSize to doRound2Dec(numFileSize / numByteUnits)
578      set strValue to (strFileSize & " Kb") as text
579    else if numFileSize < (numByteUnits * numByteUnits * numByteUnits) then
580      set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits))
581      set strValue to (strFileSize & " Mb") as text
582    else
583      set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits * numByteUnits))
584      set strValue to (strFileSize & " Gb") as text
585    end if
586  end if
587  (ocidTdElement's setStringValue:(strValue))
588  (ocidTrElement's addChild:(ocidTdElement))
589  
590  ########
591  #【修正日】をTDでセット
592  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
593  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName5))
594  (ocidTdElement's addAttribute:(ocidAddNode))
595  set strSetValue to (strFileName & " " & strItemID5) as text
596  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
597  (ocidTdElement's addAttribute:(ocidAddNode))
598  if ocidSizeA is (refMe's NSNull's |null|()) then
599    (ocidTdElement's setStringValue:(""))
600  else
601    (ocidTdElement's setStringValue:(ocidModDateAStr))
602  end if
603  #TDをTRにセット
604  (ocidTrElement's addChild:(ocidTdElement))
605  
606  ############################
607  #判定
608  ########
609  #【判定】サイズ
610  if ocidUrlA = (refMe's NSNull's |null|) then
611    #Aが無い場合
612    set strSetValueSizeChk to ("") as text
613    set strSetValueDateChk to ("") as text
614    #Bが無い場合
615  else if ocidUrlB = (refMe's NSNull's |null|) then
616    set strSetValueSizeChk to ("") as text
617    set strSetValueDateChk to ("") as text
618  else
619    #AB両方ある場合
620    if (ocidSizeA as integer) > (ocidSizeB as integer) then
621      set strSetValueSizeChk to ("←") as text
622    else if (ocidSizeA as integer) < (ocidSizeB as integer) then
623      set strSetValueSizeChk to ("→") as text
624    else
625      set strSetValueSizeChk to ("=") as text
626    end if
627    ##判定内容
628    #日付
629    set ocidDateCompare to (ocidModA's compare:(ocidModB))
630    if ocidDateCompare = (refMe's NSOrderedSame) then
631      #同じ場合
632      set strSetValueDateChk to ("=") as text
633    else if ocidDateCompare = (refMe's NSOrderedAscending) then
634      #Bが新しい場合
635      set strSetValueDateChk to ("→") as text
636    else if ocidDateCompare = (refMe's NSOrderedDescending) then
637      #Aが新しい場合
638      set strSetValueDateChk to ("←") as text
639    end if
640    
641  end if
642  #【判定】サイズ
643  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
644  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName6))
645  (ocidTdElement's addAttribute:(ocidAddNode))
646  set strSetValue to (strFileName & " " & strItemID6) as text
647  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
648  (ocidTdElement's addAttribute:(ocidAddNode))
649  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-align: center;"))
650  (ocidTdElement's addAttribute:(ocidAddNode))
651  (ocidTdElement's setStringValue:(strSetValueSizeChk))
652  #TDをTRにセット
653  (ocidTrElement's addChild:(ocidTdElement))
654  
655  
656  ########
657  #【判定】修正日
658  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
659  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName7))
660  (ocidTdElement's addAttribute:(ocidAddNode))
661  set strSetValue to (strFileName & " " & strItemID7) as text
662  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
663  (ocidTdElement's addAttribute:(ocidAddNode))
664  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-align: center;"))
665  (ocidTdElement's addAttribute:(ocidAddNode))
666  (ocidTdElement's setStringValue:(strSetValueDateChk))
667  #TDをTRにセット
668  (ocidTrElement's addChild:(ocidTdElement))
669  
670  
671  ############################
672  #後に選んだBフォルダ
673  
674  ########
675  #【パス】
676  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
677  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName8))
678  (ocidTdElement's addAttribute:(ocidAddNode))
679  set strSetValue to (strFileName & " " & strItemID8) as text
680  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
681  (ocidTdElement's addAttribute:(ocidAddNode))
682  #
683  if ocidUrlB is not (refMe's NSNull's |null|()) then
684    set ocidLabelElement to (refMe's NSXMLElement's elementWithName:("label"))
685    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("for") stringValue:("FilePath"))
686    (ocidLabelElement's addAttribute:(ocidAddNode))
687    #
688    set ocidAElement to (refMe's NSXMLElement's elementWithName:("a"))
689    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("File Link"))
690    (ocidAElement's addAttribute:(ocidAddNode))
691    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(ocidPathB))
692    (ocidAElement's addAttribute:(ocidAddNode))
693    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-decoration: none;"))
694    (ocidAElement's addAttribute:(ocidAddNode))
695    (ocidAElement's setStringValue:("●"))
696    #リンクをTDにセット
697    (ocidLabelElement's addChild:(ocidAElement))
698    #TDをTRにセット
699    (ocidTdElement's addChild:(ocidLabelElement))
700    #
701    set ocidInputElement to (refMe's NSXMLElement's elementWithName:("input"))
702    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("type") stringValue:("text"))
703    (ocidInputElement's addAttribute:(ocidAddNode))
704    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("FilePath"))
705    (ocidInputElement's addAttribute:(ocidAddNode))
706    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("name") stringValue:("FilePath"))
707    (ocidInputElement's addAttribute:(ocidAddNode))
708    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("border: none; width: 72px;"))
709    (ocidInputElement's addAttribute:(ocidAddNode))
710    set strSetValue to ocidUrlB's |path| as text
711    set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("value") stringValue:(strSetValue))
712    (ocidInputElement's addAttribute:(ocidAddNode))
713    #INPUTをTDにセット
714    (ocidTdElement's addChild:(ocidInputElement))
715  end if
716  #TDをTRにセット
717  (ocidTrElement's addChild:(ocidTdElement))
718  ########
719  #サイズ
720  ############
721  #【ファイルサイズ】TD
722  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
723  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName9))
724  (ocidTdElement's addAttribute:(ocidAddNode))
725  set strSetValue to (strFileName & " " & strItemID9) as text
726  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
727  (ocidTdElement's addAttribute:(ocidAddNode))
728  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("text-align: right;"))
729  (ocidTdElement's addAttribute:(ocidAddNode))
730  #単位による分岐
731  if ocidSizeB is (refMe's NSNull's |null|()) then
732    set strValue to ("") as text
733  else
734    set strValue to ocidSizeB as text
735    set numFileSize to strValue as integer
736    if (numFileSize) < numByteUnits then
737      set strFileSize to doRound2Dec(numFileSize)
738      set strValue to (strFileSize & " b") as text
739    else if numFileSize < (numByteUnits * numByteUnits) then
740      set strFileSize to doRound2Dec(numFileSize / numByteUnits)
741      set strValue to (strFileSize & " Kb") as text
742    else if numFileSize < (numByteUnits * numByteUnits * numByteUnits) then
743      set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits))
744      set strValue to (strFileSize & " Mb") as text
745    else
746      set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits * numByteUnits))
747      set strValue to (strFileSize & " Gb") as text
748    end if
749  end if
750  (ocidTdElement's setStringValue:(strValue))
751  (ocidTrElement's addChild:(ocidTdElement))
752  
753  ########
754  #【修正日】をTDでセット
755  set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td"))
756  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(strColName10))
757  (ocidTdElement's addAttribute:(ocidAddNode))
758  set strSetValue to (strFileName & " " & strItemID10) as text
759  set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("headers") stringValue:(strSetValue))
760  (ocidTdElement's addAttribute:(ocidAddNode))
761  if ocidModB is (refMe's NSNull's |null|()) then
762    (ocidTdElement's setStringValue:(""))
763  else
764    (ocidTdElement's setStringValue:(ocidModDateBStr))
765  end if
766  #TDをTRにセット
767  (ocidTrElement's addChild:(ocidTdElement))
768  
769  ########
770  #出来上がったTRをTBODYにセット
771  (ocidTbodyElement's addChild:(ocidTrElement))
772  #行番号カウントアップ
773  set numCntLineNo to (numCntLineNo + 1) as integer
774  log numCntLineNo & "/" & numCntAllKey
775end repeat
776
777############
778#TBODYをテーブルにセット
779(ocidTableElement's addChild:(ocidTbodyElement))
780############
781#【tfoot】 TRで
782set ocidTfootElement to (refMe's NSXMLElement's elementWithName:("tfoot"))
783set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr"))
784#colspan指定して1行でセット
785set ocidThElement to (refMe's NSXMLElement's elementWithName:("th"))
786set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり"))
787(ocidThElement's addAttribute:(ocidAddNode))
788set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text))
789(ocidThElement's addAttribute:(ocidAddNode))
790set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row"))
791(ocidThElement's addAttribute:(ocidAddNode))
792(ocidThElement's setStringValue:("サイズ←→の向きが大きい:更新日←→の向きが新しい"))
793#THをTRにセットして
794(ocidTrElement's addChild:(ocidThElement))
795#TRをTFOOTにセット
796(ocidTfootElement's addChild:(ocidTrElement))
797#TFOOTをテーブルにセット
798(ocidTableElement's addChild:(ocidTfootElement))
799##############################
800# ROOT
801##############################
802# 出来上がったテーブルをArticleエレメントにセット
803(ocidArticleElement's addChild:(ocidTableElement))
804#
805(ocidRootElement's addChild:(ocidBodyElement))
806#ROOTエレメントをXMLにセット
807ocidXMLDoc's setRootElement:(ocidRootElement)
808#読み取りやすい表示
809set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)
810
811
812
813##############################
814# 保存
815set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference)
816if (item 1 of listDone) is true then
817  log "正常終了"
818else if (item 1 of listDone) is false then
819  log (item 2 of listDone)'s localizedDescription() as text
820  return "保存に失敗しました"
821end if
822
823##############################
824# 開く
825set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
826set boolDone to appSharedWorkspace's openURL:(ocidSaveFilePathURL)
827if (boolDone as boolean) is false then
828  #ファイルを開く
829  set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias
830  tell application "Finder"
831    try
832      open file aliasSaveFilePath
833    end try
834  end tell
835end if
836#
837set ocidSaveFilePath to ocidSaveFilePathURL's |path|
838set ocidContainerDirPath to ocidSaveDirPathURL's |path|
839set boolDone to appSharedWorkspace's selectFile:(ocidSaveFilePath) inFileViewerRootedAtPath:(ocidContainerDirPath)
840if (boolDone as boolean) is false then
841  #ファイルを開く
842  set aliasSaveDirPath to (ocidSaveDirPathURL's absoluteURL()) as alias
843  tell application "Finder"
844    try
845      open folder aliasSaveDirPath
846    end try
847  end tell
848end if
849
850
851##############################
852# 基本的なHTMLの構造
853##############################
854to doMakeRootElement()
855  #
856  set ocidRootElement to refMe's NSXMLElement's elementWithName:("html")
857  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja")
858  ocidRootElement's addAttribute:(ocidAddNode)
859  #
860  set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head")
861  #
862  set ocidAddElement to refMe's NSXMLElement's elementWithName:("title")
863  ocidAddElement's setStringValue:("ファイル比較")
864  ocidHeadElement's addChild:(ocidAddElement)
865  # http-equiv
866  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
867  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type")
868  ocidAddElement's addAttribute:(ocidAddNode)
869  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8")
870  ocidAddElement's addAttribute:(ocidAddNode)
871  ocidHeadElement's addChild:(ocidAddElement)
872  #
873  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
874  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type")
875  ocidAddElement's addAttribute:(ocidAddNode)
876  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css")
877  ocidAddElement's addAttribute:(ocidAddNode)
878  ocidHeadElement's addChild:(ocidAddElement)
879  #
880  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
881  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type")
882  ocidAddElement's addAttribute:(ocidAddNode)
883  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript")
884  ocidAddElement's addAttribute:(ocidAddNode)
885  ocidHeadElement's addChild:(ocidAddElement)
886  #
887  set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta")
888  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport")
889  ocidAddElement's addAttribute:(ocidAddNode)
890  set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720")
891  ocidAddElement's addAttribute:(ocidAddNode)
892  ocidHeadElement's addChild:(ocidAddElement)
893  #
894  set ocidAddElement to refMe's NSXMLElement's elementWithName:("style")
895  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 }} thead td {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 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 }}")
896  ocidHeadElement's addChild:(ocidAddElement)
897  #
898  ocidRootElement's addChild:(ocidHeadElement)
899  #
900  return ocidRootElement
901end doMakeRootElement
902
903##############################
904# 小数点以下2桁処理
905##############################
906
907to doRound2Dec(argNumber)
908  set strDecNo to ((round (argNumber * 100)) / 100) as text
909  return strDecNo
910end doRound2Dec
911
912################################
913# 明日の日付 doGetDateNo(argDateFormat,argCalendarNO)
914# argCalendarNO 1 NSCalendarIdentifierGregorian 西暦
915# argCalendarNO 2 NSCalendarIdentifierJapanese 和暦
916################################
917to doGetNextDateNo({argDateFormat, argCalendarNO})
918  ##渡された値をテキストで確定させて
919  set strDateFormat to argDateFormat as text
920  set intCalendarNO to argCalendarNO as integer
921  ###日付情報の取得
922  set ocidDate to current application's NSDate's |date|()
923  set ocidIntervalt to current application's NSDate's dateWithTimeIntervalSinceNow:(86400)
924  ###日付のフォーマットを定義(日本語)
925  set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init()
926  ###和暦 西暦 カレンダー分岐
927  if intCalendarNO = 1 then
928    set ocidCalendarID to (current application's NSCalendarIdentifierGregorian)
929  else if intCalendarNO = 2 then
930    set ocidCalendarID to (current application's NSCalendarIdentifierJapanese)
931  else
932    set ocidCalendarID to (current application's NSCalendarIdentifierISO8601)
933  end if
934  set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID)
935  set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo")
936  set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX")
937  ###設定
938  ocidFormatterJP's setTimeZone:(ocidTimezoneJP)
939  ocidFormatterJP's setLocale:(ocidLocaleJP)
940  ocidFormatterJP's setCalendar:(ocidCalendarJP)
941  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle)
942  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle)
943  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle)
944  # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle)
945  ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle)
946  ###渡された値でフォーマット定義
947  ocidFormatterJP's setDateFormat:(strDateFormat)
948  ###フォーマット適応
949  set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidIntervalt)
950  ###テキストで戻す
951  set strDateAndTime to ocidDateAndTime as text
952  return strDateAndTime
953end doGetNextDateNo
AppleScriptで生成しました

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom