
【クイック・アクション】フォルダ内のファイル情報(ファイルリスト)をHTMLで出力する(修正版)
【Safari・FireFox用Script Editorで開く】 |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 | 別名で保存から アプリケーションで保存でドロップレットになります |
| 006 | |
| 007 | v1初回作成 |
| 008 | v2 一部のメディアのピクセルサイズの取得に対応 |
| 009 | v2.1 書き込み権限のない場所の場合はダイアログ表示して保存はデスクトップ |
| 010 | v2.2 ファイルが画像の場合はサムネイル表示を入れた |
| 011 | v2.2.1 URL部分を%エンコードするようにした |
| 012 | v2.2.2 合計ファイルサイズが0になる不具合を修正した |
| 013 | |
| 014 | com.cocolog-nifty.quicktimer.icefloe *) |
| 015 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 016 | use AppleScript version "2.8" |
| 017 | use framework "Foundation" |
| 018 | use framework "AppKit" |
| 019 | use framework "UniformTypeIdentifiers" |
| 020 | use framework "CoreMedia" |
| 021 | use scripting additions |
| 022 | property refMe : a reference to current application |
| 023 | |
| 024 | ############################ |
| 025 | #Wクリックで起動した場合 |
| 026 | #on run {argListAliasDirPath} |
| 027 | (* |
| 028 | #テスト用 |
| 029 | *) |
| 030 | on run |
| 031 | |
| 032 | ##デフォルト=デスクトップ |
| 033 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 034 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 035 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
| 036 | set aliasDesktopDirPath to (ocidDesktopDirPathURL's absoluteURL()) as alias |
| 037 | set strPromptText to ("フォルダをえらんでください") as text |
| 038 | set strMesText to ("フォルダをえらんでください") as text |
| 039 | try |
| 040 | ###ダイアログを前面に出す |
| 041 | tell application "SystemUIServer" |
| 042 | activate |
| 043 | set argListAliasDirPath to (choose folder strMesText with prompt strPromptText default location aliasDesktopDirPath with invisibles, showing package contents and multiple selections allowed) as list |
| 044 | end tell |
| 045 | on error strErrMes number numErrNo |
| 046 | log strErrMes & numErrNo |
| 047 | return false |
| 048 | end try |
| 049 | |
| 050 | |
| 051 | set boolDone to (open argListAliasDirPath) |
| 052 | log doQuitAutomatorRunner() |
| 053 | return |
| 054 | end run |
| 055 | |
| 056 | ############################ |
| 057 | #ドロップで起動した場合 |
| 058 | on open argListAliasDirPath |
| 059 | #カレント |
| 060 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 061 | set ocidHomeDirURL to appFileManager's homeDirectoryForCurrentUser() |
| 062 | set strHomeDirURL to ocidHomeDirURL's |path|() as text |
| 063 | |
| 064 | #本来この処理は不要なんだけどドロップレットにするのも見越して |
| 065 | #次工程に回すArray |
| 066 | set ocidDirPathArray to refMe's NSMutableArray's alloc()'s init() |
| 067 | |
| 068 | repeat with itemAliasDirPath in argListAliasDirPath |
| 069 | #パス |
| 070 | set aliasDirPath to itemAliasDirPath as alias |
| 071 | set strDirPath to (POSIX path of aliasDirPath) as text |
| 072 | if (strDirPath contains strHomeDirURL) is false then |
| 073 | tell application "System Events" |
| 074 | activate |
| 075 | display alert "ユーザーディレクトリ外です。書き込みアクセス権がない可能性があるので正しいHTMLが生成されない可能性があります" |
| 076 | end tell |
| 077 | end if |
| 078 | set ocidDirPathStr to (refMe's NSString's stringWithString:(strDirPath)) |
| 079 | set ocidDirPath to ocidDirPathStr's stringByStandardizingPath() |
| 080 | set ocidDirPathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidDirPath)) |
| 081 | #フォルダ判定 |
| 082 | set listResponse to (ocidDirPathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsDirectoryKey) |error|:(reference)) |
| 083 | set boolIsDir to (2nd item of listResponse) as boolean |
| 084 | if boolIsDir is true then |
| 085 | (ocidDirPathArray's addObject:(ocidDirPathURL)) |
| 086 | end if |
| 087 | end repeat |
| 088 | |
| 089 | set boolDone to doMakeHTML(ocidDirPathArray) |
| 090 | return boolDone |
| 091 | end open |
| 092 | |
| 093 | |
| 094 | |
| 095 | |
| 096 | on doMakeHTML(argArrayDirPathURL) |
| 097 | |
| 098 | repeat with ocidDirPathURL in argArrayDirPathURL |
| 099 | ##フォルダ名→保存先HTMLパス |
| 100 | set ocidContainerDirPathURL to ocidDirPathURL's URLByDeletingLastPathComponent() |
| 101 | set ocidContainerDirPath to ocidDirPathURL's |path|() |
| 102 | set ocidDirName to ocidDirPathURL's lastPathComponent() |
| 103 | set ocidSaveFileName to refMe's NSMutableString's alloc()'s init() |
| 104 | (ocidSaveFileName's appendString:("_ファイルリスト@")) |
| 105 | (ocidSaveFileName's appendString:(ocidDirName)) |
| 106 | set ocidBaseFilePathURL to (ocidDirPathURL's URLByAppendingPathComponent:(ocidSaveFileName)) |
| 107 | set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:("html")) |
| 108 | set ocidDirPathURLString to ocidDirPathURL's absoluteString() |
| 109 | |
| 110 | ##ファイルの各種プロパティを取得 |
| 111 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 112 | set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles |
| 113 | set ocidPropertieArray to refMe's NSMutableArray's alloc()'s init() |
| 114 | (ocidPropertieArray's addObject:(refMe's NSURLPathKey)) |
| 115 | (ocidPropertieArray's addObject:(refMe's NSURLFileSizeKey)) |
| 116 | (ocidPropertieArray's addObject:(refMe's NSURLCreationDateKey)) |
| 117 | (ocidPropertieArray's addObject:(refMe's NSURLContentModificationDateKey)) |
| 118 | (ocidPropertieArray's addObject:(refMe's NSURLNameKey)) |
| 119 | (ocidPropertieArray's addObject:(refMe's NSURLContentTypeKey)) |
| 120 | (ocidPropertieArray's addObject:(refMe's NSURLFileAllocatedSizeKey)) |
| 121 | (ocidPropertieArray's addObject:(refMe's NSURLIsRegularFileKey)) |
| 122 | |
| 123 | ######################################## |
| 124 | ##コンテンツの収集 A 第一階層のみの場合 |
| 125 | ######################################## |
| 126 | (* |
| 127 | set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidDirPathURL) includingPropertiesForKeys:(ocidPropertieArray) options:(ocidOption) |error|:(reference)) |
| 128 | set ocidFilePathURLArray to item 1 of listResponse |
| 129 | #パスリストをファイル名でソート並び替え |
| 130 | set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("lastPathComponent") ascending:(yes) selector:("localizedStandardCompare:") |
| 131 | set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor) |
| 132 | set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray) |
| 133 | *) |
| 134 | ######################################## |
| 135 | ##コンテンツの収集 B 最下層までの場合 |
| 136 | ######################################## |
| 137 | set ocidEmuDict to (appFileManager's enumeratorAtURL:(ocidDirPathURL) includingPropertiesForKeys:(ocidPropertieArray) options:(ocidOption) errorHandler:(reference)) |
| 138 | set ocidEmuFileURLArray to ocidEmuDict's allObjects() |
| 139 | set ocidFilePathURLAllArray to refMe's NSMutableArray's alloc()'s init() |
| 140 | (ocidFilePathURLAllArray's addObjectsFromArray:(ocidEmuFileURLArray)) |
| 141 | # |
| 142 | set ocidFilePathURLArray to refMe's NSMutableArray's alloc()'s init() |
| 143 | repeat with itemFilePathURL in ocidFilePathURLAllArray |
| 144 | set listResult to (itemFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error|:(reference)) |
| 145 | set boolIsRegularFileKey to (2nd item of listResult) |
| 146 | if boolIsRegularFileKey is (refMe's NSNumber's numberWithBool:true) then |
| 147 | #リストにする |
| 148 | (ocidFilePathURLArray's addObject:(itemFilePathURL)) |
| 149 | end if |
| 150 | end repeat |
| 151 | #パスリストをファイル名でソート並び替え absoluteString localizedStandardCompare |
| 152 | set ocidDescriptor to (refMe's NSSortDescriptor's sortDescriptorWithKey:("path") ascending:(true) selector:"localizedStandardCompare:") |
| 153 | set ocidDescriptorArray to (refMe's NSArray's arrayWithObject:(ocidDescriptor)) |
| 154 | set ocidSortedArray to (ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)) |
| 155 | |
| 156 | ############################## |
| 157 | # XML 生成開始 |
| 158 | ############################## |
| 159 | #XML初期化 |
| 160 | set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init() |
| 161 | (ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind)) |
| 162 | # DTD付与 |
| 163 | set ocidDTD to refMe's NSXMLDTD's alloc()'s init() |
| 164 | (ocidDTD's setName:("html")) |
| 165 | (ocidXMLDoc's setDTD:(ocidDTD)) |
| 166 | # XML主要部分を生成 |
| 167 | set ocidRootElement to doMakeRootElement() |
| 168 | #ボディエレメント |
| 169 | set ocidBodyElement to (refMe's NSXMLElement's elementWithName:("body")) |
| 170 | #ヘッダー |
| 171 | set ocidHeaderElement to (refMe's NSXMLElement's elementWithName:("header")) |
| 172 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("header")) |
| 173 | (ocidHeaderElement's addAttribute:(ocidAddNode)) |
| 174 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header")) |
| 175 | (ocidHeaderElement's addAttribute:(ocidAddNode)) |
| 176 | (ocidBodyElement's addChild:(ocidHeaderElement)) |
| 177 | #アーティクル |
| 178 | set ocidArticleElement to (refMe's NSXMLElement's elementWithName:("article")) |
| 179 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("article")) |
| 180 | (ocidArticleElement's addAttribute:(ocidAddNode)) |
| 181 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article")) |
| 182 | (ocidArticleElement's addAttribute:(ocidAddNode)) |
| 183 | set ocidH4Element to (refMe's NSXMLElement's elementWithName:("H4")) |
| 184 | set strDateNo to doGetDateNoString("yyyyMMdd HHmm") as text |
| 185 | (ocidH4Element's setStringValue:("ファイルリスト:" & strDateNo & "作成")) |
| 186 | (ocidArticleElement's addChild:(ocidH4Element)) |
| 187 | (ocidBodyElement's addChild:(ocidArticleElement)) |
| 188 | #フッター |
| 189 | set ocidFooterElement to (refMe's NSXMLElement's elementWithName:("footer")) |
| 190 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer")) |
| 191 | (ocidFooterElement's addAttribute:(ocidAddNode)) |
| 192 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer")) |
| 193 | (ocidFooterElement's addAttribute:(ocidAddNode)) |
| 194 | #リンク付与(不要なら削除可) |
| 195 | set ocidAElement to (refMe's NSXMLElement's elementWithName:("a")) |
| 196 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://note.com/quicktimer")) |
| 197 | (ocidAElement's addAttribute:(ocidAddNode)) |
| 198 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
| 199 | (ocidAElement's addAttribute:(ocidAddNode)) |
| 200 | set strContents to ("AppleScriptで作成しました") as text |
| 201 | (ocidAElement's setStringValue:(strContents)) |
| 202 | (ocidFooterElement's addChild:(ocidAElement)) |
| 203 | (ocidBodyElement's addChild:(ocidFooterElement)) |
| 204 | ############################## |
| 205 | # TABLE コンテンツ部分生成開始 |
| 206 | ############################## |
| 207 | #テーブル部生成開始 |
| 208 | set ocidTableElement to (refMe's NSXMLElement's elementWithName:("table")) |
| 209 | #【caption】 |
| 210 | set ocidCaptionElement to (refMe's NSXMLElement's elementWithName:("caption")) |
| 211 | (ocidCaptionElement's setStringValue:("【ファイルリスト】: 行番号に※表示はCMYKデータ(PDFを除く)")) |
| 212 | (ocidTableElement's addChild:(ocidCaptionElement)) |
| 213 | #【colgroup】 |
| 214 | set ocidColgroupElement to (refMe's NSXMLElement's elementWithName:("colgroup")) |
| 215 | #テーブルのタイトル部 |
| 216 | set listColName to {"番号", "ファイル名", "サイズ", "Pxサイズ", "種類", "作成日", "修正日"} as list |
| 217 | #タイトル部の数だけ繰り返し |
| 218 | repeat with itemColName in listColName |
| 219 | #【col】col生成 |
| 220 | set ocidAddElement to (refMe's NSXMLElement's elementWithName:("col")) |
| 221 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName)) |
| 222 | (ocidAddElement's addAttribute:(ocidAddNode)) |
| 223 | (ocidColgroupElement's addChild:(ocidAddElement)) |
| 224 | end repeat |
| 225 | #テーブルエレメントに追加 |
| 226 | (ocidTableElement's addChild:(ocidColgroupElement)) |
| 227 | #【thead】 |
| 228 | set ocidTheadElement to (refMe's NSXMLElement's elementWithName:("thead")) |
| 229 | #TR |
| 230 | set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr")) |
| 231 | #タイトル部の数だけ繰り返し |
| 232 | repeat with itemColName in listColName |
| 233 | #ここはTDではなくてTHを利用 |
| 234 | set ocidAddElement to (refMe's NSXMLElement's elementWithName:("th")) |
| 235 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:(itemColName)) |
| 236 | (ocidAddElement's addAttribute:(ocidAddNode)) |
| 237 | #値を入れる |
| 238 | (ocidAddElement's setStringValue:(itemColName)) |
| 239 | #TH→TRにセット |
| 240 | (ocidTrElement's addChild:(ocidAddElement)) |
| 241 | end repeat |
| 242 | #TRをTHEADにセット |
| 243 | (ocidTheadElement's addChild:(ocidTrElement)) |
| 244 | #THEADをテーブルにセット |
| 245 | (ocidTableElement's addChild:(ocidTheadElement)) |
| 246 | #【tbody】 |
| 247 | set ocidTbodyElement to (refMe's NSXMLElement's elementWithName:("tbody")) |
| 248 | #行番号 |
| 249 | set numCntLineNo to 1 as integer |
| 250 | #合計ファイルサイズ用 |
| 251 | set numAllFileSize to 0 as integer |
| 252 | #ファイルのパスの数だけ繰り返し |
| 253 | repeat with itemFilePathURL in ocidSortedArray |
| 254 | ##UTIを求めて |
| 255 | set listResourceValue to (itemFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLContentTypeKey) |error|:(reference)) |
| 256 | set ocidContentType to (item 2 of listResourceValue) |
| 257 | set strUTI to (ocidContentType's identifier) as text |
| 258 | ######### |
| 259 | set strUTILIST to "public.png,public.jpeg,com.adobe.photoshop-image,public.tiff,com.apple.icns,public.heic" as text |
| 260 | if strUTILIST contains strUTI then |
| 261 | log "CMYKチェック対象ファイル" |
| 262 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithContentsOfURL:(itemFilePathURL)) |
| 263 | set ocidImageRepArray to ocidReadImage's representations() |
| 264 | set ocidImageRep to ocidImageRepArray's firstObject() |
| 265 | #画像サイズと解像度 |
| 266 | set numPxW to ocidImageRep's pixelsWide() |
| 267 | set numPxH to ocidImageRep's pixelsHigh() |
| 268 | set ocidPtSize to ocidReadImage's |size|() |
| 269 | set numPtW to ocidPtSize's width() |
| 270 | set numPtH to ocidPtSize's height() |
| 271 | # |
| 272 | #計算に必要な値 |
| 273 | set ocidDecPt to (refMe's NSDecimalNumber's alloc()'s initWithString:("72")) |
| 274 | set ocidDecIn to (refMe's NSDecimalNumber's alloc()'s initWithString:("25.4")) |
| 275 | # |
| 276 | set ocidDecWpx to (refMe's NSDecimalNumber's alloc()'s initWithString:(numPxW as text)) |
| 277 | set ocidDecHpx to (refMe's NSDecimalNumber's alloc()'s initWithString:(numPxH as text)) |
| 278 | set ocidDecWpt to (refMe's NSDecimalNumber's alloc()'s initWithString:(numPtW as text)) |
| 279 | set ocidDecHpt to (refMe's NSDecimalNumber's alloc()'s initWithString:(numPtH as text)) |
| 280 | set ocidResolutioPxW to (ocidDecWpx's decimalNumberByDividingBy:(ocidDecWpt)) |
| 281 | set ocidResolutinW to (ocidResolutioPxW's decimalNumberByMultiplyingBy:(ocidDecPt)) |
| 282 | set ocidResolutioPxH to (ocidDecHpx's decimalNumberByDividingBy:(ocidDecHpt)) |
| 283 | set ocidResolutinH to (ocidResolutioPxH's decimalNumberByMultiplyingBy:(ocidDecPt)) |
| 284 | |
| 285 | #小数点以下2位で四捨五入 |
| 286 | set appFormatter to refMe's NSNumberFormatter's alloc()'s init() |
| 287 | (appFormatter's setRoundingMode:(refMe's NSNumberFormatterRoundUp)) |
| 288 | (appFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)) |
| 289 | (appFormatter's setMaximumFractionDigits:(2)) |
| 290 | #解像度は桁揃えしておく |
| 291 | set ocidResolutionW to (appFormatter's stringFromNumber:(ocidResolutinW)) |
| 292 | set ocidResolutionH to (appFormatter's stringFromNumber:(ocidResolutinH)) |
| 293 | #HTML表示用解像度 |
| 294 | set strSetResValueA to ((numPxW as text) & " x " & (ocidDecHpx as text) & " px") as text |
| 295 | set strSetResValueB to ("(" & ocidResolutionH & " ppi)") as text |
| 296 | ####### |
| 297 | set ocidColorSpace to ocidImageRep's colorSpace() |
| 298 | #シンプルにコンポーネント番号で判定する場合 |
| 299 | # 1 = GS 3=RGB 4=CMYK |
| 300 | set numColorCompNo to ocidColorSpace's numberOfColorComponents as integer |
| 301 | #colorSpaceModelで判定したい場合 |
| 302 | # set ocidColorModel to ocidColorSpace's colorSpaceModel() |
| 303 | # if ocidColorModel = (refMe's NSColorSpaceModelCMYK) then |
| 304 | log numColorCompNo |
| 305 | if numColorCompNo = 4 then |
| 306 | log "CMYYKデータです" |
| 307 | set ocidReadImage to (missing value) |
| 308 | set ocidImageRep to (missing value) |
| 309 | set boolCMYK to true as boolean |
| 310 | else |
| 311 | set boolCMYK to false as boolean |
| 312 | end if |
| 313 | else |
| 314 | set strSetResValueA to ("") as text |
| 315 | set strSetResValueB to ("") as text |
| 316 | set boolCMYK to false as boolean |
| 317 | end if |
| 318 | set strUTILIST to "public.movie,public.mpeg-4" as text |
| 319 | if strUTILIST contains strUTI then |
| 320 | set ocidReadAsset to (refMe's AVAsset's assetWithURL:(itemFilePathURL)) |
| 321 | set ocidReadAssetTrackArray to ocidReadAsset's tracks() |
| 322 | set ocidTrack to (ocidReadAssetTrackArray's firstObject()) |
| 323 | if ocidTrack = (missing value) then |
| 324 | set strSetResValueA to ("") as text |
| 325 | set strSetResValueB to ("") as text |
| 326 | else |
| 327 | set recordAssetTrackNaturalSize to ocidTrack's naturalSize() |
| 328 | set numTrackWidth to (width of recordAssetTrackNaturalSize) as integer |
| 329 | set numrackHeight to (height of recordAssetTrackNaturalSize) as integer |
| 330 | set strTrackWidth to (numTrackWidth) as text |
| 331 | set strTrackHeight to (numrackHeight) as text |
| 332 | set strSetResValueA to (strTrackWidth & " x " & strTrackHeight & "") as text |
| 333 | set strSetResValueB to ("") as text |
| 334 | end if |
| 335 | end if |
| 336 | |
| 337 | ## |
| 338 | #ファイルのリソースを取得 |
| 339 | set listResponse to (itemFilePathURL's resourceValuesForKeys:(ocidPropertieArray) |error|:(reference)) |
| 340 | set ocidValueDict to (first item of listResponse) |
| 341 | #TRの開始 |
| 342 | set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr")) |
| 343 | #【行番号】をTHでセット |
| 344 | set strZeroSupp to ("00") as text |
| 345 | set strZeroSupp to ("00" & numCntLineNo) as text |
| 346 | set strLineNO to (text -3 through -1 of strZeroSupp) as text |
| 347 | set ocidThElement to (refMe's NSXMLElement's elementWithName:("th")) |
| 348 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("番号")) |
| 349 | (ocidThElement's addAttribute:(ocidAddNode)) |
| 350 | if boolCMYK is true then |
| 351 | set strSetLineNO to (strLineNO & "*") as text |
| 352 | else if boolCMYK is false then |
| 353 | set strSetLineNO to (strLineNO) as text |
| 354 | end if |
| 355 | (ocidThElement's setStringValue:(strSetLineNO)) |
| 356 | (ocidTrElement's addChild:(ocidThElement)) |
| 357 | #【ファイル名】をTDでセット |
| 358 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLNameKey)) |
| 359 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
| 360 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("ファイル名")) |
| 361 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 362 | #### |
| 363 | set itemFilePath to itemFilePathURL's |path|() |
| 364 | set ocidRange to (itemFilePath's rangeOfString:(ocidContainerDirPath)) |
| 365 | set numLength to (|length| of ocidRange) + 1 as integer |
| 366 | set ocidRlativePath to (itemFilePath's substringFromIndex:(numLength)) |
| 367 | |
| 368 | #↑のTDの内容=ファイル名にリンクを付与 |
| 369 | set ocidAElement to (refMe's NSXMLElement's elementWithName:("a")) |
| 370 | set ocidCharSet to refMe's NSCharacterSet's URLPathAllowedCharacterSet() |
| 371 | set ocidEncFileName to (ocidRlativePath's stringByAddingPercentEncodingWithAllowedCharacters:(ocidCharSet)) |
| 372 | |
| 373 | set strEncHref to ("./" & ocidEncFileName) as text |
| 374 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strEncHref)) |
| 375 | (ocidAElement's addAttribute:(ocidAddNode)) |
| 376 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
| 377 | (ocidAElement's addAttribute:(ocidAddNode)) |
| 378 | set strHref to (ocidRlativePath) as text |
| 379 | (ocidAElement's setStringValue:(strHref)) |
| 380 | #リンクをTDにセット |
| 381 | (ocidTdElement's addChild:(ocidAElement)) |
| 382 | #画像の場合にサムネイルを出すように |
| 383 | set listImgUTI to {"public.png", "public.jpeg", "com.adobe.photoshop-image", "public.tiff", "public.heic"} as list |
| 384 | log strUTI |
| 385 | if listImgUTI contains strUTI then |
| 386 | set ocidImgElement to (refMe's NSXMLElement's elementWithName:("img")) |
| 387 | set ocidCharSet to refMe's NSCharacterSet's URLPathAllowedCharacterSet() |
| 388 | set ocidEncFileName to (ocidRlativePath's stringByAddingPercentEncodingWithAllowedCharacters:(ocidCharSet)) |
| 389 | set strEncHref to ("./" & ocidEncFileName) as text |
| 390 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("src") stringValue:(strEncHref)) |
| 391 | (ocidImgElement's addAttribute:(ocidAddNode)) |
| 392 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("alt") stringValue:("画像ファイルのサムネイル")) |
| 393 | (ocidImgElement's addAttribute:(ocidAddNode)) |
| 394 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("style") stringValue:("max-width: 40px;max-height: 40px;")) |
| 395 | (ocidImgElement's addAttribute:(ocidAddNode)) |
| 396 | (ocidTdElement's addChild:(ocidImgElement)) |
| 397 | end if |
| 398 | #TDをTRにセット |
| 399 | (ocidTrElement's addChild:(ocidTdElement)) |
| 400 | |
| 401 | #【ファイルサイズ】TD |
| 402 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLFileSizeKey)) |
| 403 | #ファイルサイズの合計に加算 |
| 404 | set strValue to ocidValue as text |
| 405 | set numValue to strValue as integer |
| 406 | set numAllFileSize to (numAllFileSize + numValue) |
| 407 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
| 408 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("ファイルサイズ")) |
| 409 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 410 | #単位による分岐 |
| 411 | set numValue to ocidValue's intValue() as number |
| 412 | set numFileSize to numValue as integer |
| 413 | # |
| 414 | set numByteUnits to 1000 as integer |
| 415 | # バイト単位 10.5以前やWindowsターゲットの場合は1024に |
| 416 | log numFileSize |
| 417 | log numByteUnits |
| 418 | if (numFileSize) < numByteUnits then |
| 419 | log "b:バイト単位" |
| 420 | set strFileSize to doRound2Dec(numFileSize) |
| 421 | set strValue to (strFileSize & " b") as text |
| 422 | else if numFileSize < (numByteUnits * numByteUnits) then |
| 423 | log "kb:キロバイト単位" |
| 424 | set strFileSize to doRound2Dec(numFileSize / numByteUnits) |
| 425 | set strValue to (strFileSize & " Kb") as text |
| 426 | else if numFileSize < (numByteUnits * numByteUnits * numByteUnits) then |
| 427 | log "mb:メガバイト単位" |
| 428 | set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits)) |
| 429 | set strValue to (strFileSize & " Mb") as text |
| 430 | else |
| 431 | log "gb:ギガバイト単位" |
| 432 | set strFileSize to doRound2Dec(numFileSize / (numByteUnits * numByteUnits * numByteUnits)) |
| 433 | set strValue to (strFileSize & " Gb") as text |
| 434 | end if |
| 435 | (ocidTdElement's setStringValue:(strValue)) |
| 436 | (ocidTrElement's addChild:(ocidTdElement)) |
| 437 | #【種類】TDでセット |
| 438 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLContentTypeKey))'s localizedDescription() |
| 439 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
| 440 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("解像度")) |
| 441 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 442 | # set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("kind_string")) |
| 443 | # (ocidTdElement's addAttribute:(ocidAddNode)) |
| 444 | # |
| 445 | set ocidPElement to (refMe's NSXMLElement's elementWithName:("p")) |
| 446 | (ocidPElement's setStringValue:(strSetResValueA)) |
| 447 | set ocidSmallElement to (refMe's NSXMLElement's elementWithName:("small")) |
| 448 | (ocidSmallElement's setStringValue:(strSetResValueB)) |
| 449 | (ocidTdElement's addChild:(ocidPElement)) |
| 450 | (ocidTdElement's addChild:(ocidSmallElement)) |
| 451 | |
| 452 | (ocidTrElement's addChild:(ocidTdElement)) |
| 453 | |
| 454 | |
| 455 | |
| 456 | #【種類】TDでセット |
| 457 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLContentTypeKey))'s localizedDescription() |
| 458 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
| 459 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("種類")) |
| 460 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 461 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("kind_string")) |
| 462 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 463 | (ocidTdElement's setStringValue:(ocidValue)) |
| 464 | (ocidTrElement's addChild:(ocidTdElement)) |
| 465 | #【作成日】TDでセット |
| 466 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLCreationDateKey)) |
| 467 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
| 468 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("作成")) |
| 469 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 470 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("date_string")) |
| 471 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 472 | set strDate to doGetDateNo(ocidValue) |
| 473 | (ocidTdElement's setStringValue:(strDate)) |
| 474 | (ocidTrElement's addChild:(ocidTdElement)) |
| 475 | #【修正日】TDでセット |
| 476 | set ocidValue to (ocidValueDict's valueForKey:(refMe's NSURLContentModificationDateKey)) |
| 477 | set ocidTdElement to (refMe's NSXMLElement's elementWithName:("td")) |
| 478 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("修正日")) |
| 479 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 480 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("date_string")) |
| 481 | (ocidTdElement's addAttribute:(ocidAddNode)) |
| 482 | set strDate to doGetDateNo(ocidValue) |
| 483 | (ocidTdElement's setStringValue:(strDate)) |
| 484 | (ocidTrElement's addChild:(ocidTdElement)) |
| 485 | #出来上がったTRをTBODYにセット |
| 486 | (ocidTbodyElement's addChild:(ocidTrElement)) |
| 487 | #項目番号のカウントアップ |
| 488 | set numCntLineNo to (numCntLineNo + 1) as integer |
| 489 | end repeat |
| 490 | #TBODYをテーブルにセット |
| 491 | (ocidTableElement's addChild:(ocidTbodyElement)) |
| 492 | #【tfoot】 TRで |
| 493 | set ocidTfootElement to (refMe's NSXMLElement's elementWithName:("tfoot")) |
| 494 | set ocidTrElement to (refMe's NSXMLElement's elementWithName:("tr")) |
| 495 | #項目数を取得して |
| 496 | set numCntCol to (count of listColName) as integer |
| 497 | #colspan指定して1行でセット |
| 498 | set ocidThElement to (refMe's NSXMLElement's elementWithName:("th")) |
| 499 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("テーブルの終わり")) |
| 500 | (ocidThElement's addAttribute:(ocidAddNode)) |
| 501 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("colspan") stringValue:(numCntCol as text)) |
| 502 | (ocidThElement's addAttribute:(ocidAddNode)) |
| 503 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("scope") stringValue:("row")) |
| 504 | (ocidThElement's addAttribute:(ocidAddNode)) |
| 505 | # |
| 506 | set numByteUnits to 1000 as integer |
| 507 | # バイト単位 10.5以前やWindowsターゲットの場合は1024に |
| 508 | if numAllFileSize < numByteUnits then |
| 509 | log "b:バイト単位" |
| 510 | set strFileSize to doRound2Dec(numAllFileSize) |
| 511 | set strValue to "フォルダ合計:" & strFileSize & " b" as text |
| 512 | |
| 513 | else if numAllFileSize < (numByteUnits * numByteUnits) then |
| 514 | log "kb:キロバイト単位" |
| 515 | set strFileSize to doRound2Dec(numAllFileSize / numByteUnits) |
| 516 | set strValue to "フォルダ合計:" & strFileSize & " Kb" as text |
| 517 | |
| 518 | else if numAllFileSize < (numByteUnits * numByteUnits * numByteUnits) then |
| 519 | log "mb:メガバイト単位" |
| 520 | set strFileSize to doRound2Dec(numAllFileSize / (numByteUnits * numByteUnits)) |
| 521 | set strValue to "フォルダ合計:" & strFileSize & " Mb" as text |
| 522 | else |
| 523 | log "gb:ギガバイト単位" |
| 524 | set strFileSize to doRound2Dec(numAllFileSize / (numByteUnits * numByteUnits * numByteUnits)) |
| 525 | set strValue to "フォルダ合計:" & strFileSize & " Gb" as text |
| 526 | end if |
| 527 | |
| 528 | |
| 529 | |
| 530 | if (numAllFileSize) < 100000 then |
| 531 | set numValue to (numAllFileSize / 1000) as integer |
| 532 | set strValue to "フォルダ合計:" & numValue & " Kb" as text |
| 533 | else if (numAllFileSize) > (10000 * 100000) then |
| 534 | set numValue to (numAllFileSize / (10000 * 100000)) |
| 535 | set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init() |
| 536 | (ocidFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)) |
| 537 | (ocidFormatter's setMinimumFractionDigits:(2)) |
| 538 | (ocidFormatter's setMaximumFractionDigits:(2)) |
| 539 | set strValue to (ocidFormatter's stringFromNumber:(numValue)) as text |
| 540 | set strValue to "フォルダ合計:" & strValue & " Gb" as text |
| 541 | |
| 542 | else |
| 543 | set numValue to (numAllFileSize / 1000000) |
| 544 | set ocidFormatter to refMe's NSNumberFormatter's alloc()'s init() |
| 545 | (ocidFormatter's setNumberStyle:(refMe's NSNumberFormatterDecimalStyle)) |
| 546 | (ocidFormatter's setMinimumFractionDigits:(2)) |
| 547 | (ocidFormatter's setMaximumFractionDigits:(2)) |
| 548 | set strValue to (ocidFormatter's stringFromNumber:(numValue)) as text |
| 549 | |
| 550 | set strValue to "フォルダ合計:" & numValue & " Mb" as text |
| 551 | end if |
| 552 | (ocidThElement's setStringValue:(strValue)) |
| 553 | |
| 554 | #THをTRにセットして |
| 555 | (ocidTrElement's addChild:(ocidThElement)) |
| 556 | #TRをTFOOTにセット |
| 557 | (ocidTfootElement's addChild:(ocidTrElement)) |
| 558 | #TFOOTをテーブルにセット |
| 559 | (ocidTableElement's addChild:(ocidTfootElement)) |
| 560 | # 出来上がったテーブルをArticleエレメントにセット |
| 561 | (ocidArticleElement's addChild:(ocidTableElement)) |
| 562 | # |
| 563 | (ocidRootElement's addChild:(ocidBodyElement)) |
| 564 | ############################## |
| 565 | # TABLE |
| 566 | ############################## |
| 567 | #ROOTエレメントをXMLにセット |
| 568 | (ocidXMLDoc's setRootElement:(ocidRootElement)) |
| 569 | #読み取りやすい表示 |
| 570 | set ocidXMLdata to (ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint)) |
| 571 | #保存 |
| 572 | set listDone to (ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error|:(reference)) |
| 573 | #保存に失敗したらデスクトップに作成する |
| 574 | if (first item of listDone) is false then |
| 575 | set ocidXMLString to ocidXMLDoc's XMLString() |
| 576 | set strSetValue to ("<a href=\"file://" & ocidContainerDirPath & "/") |
| 577 | set ocidXMLString to (ocidXMLString's stringByReplacingOccurrencesOfString:("<a href=\"./") withString:(strSetValue)) |
| 578 | tell application "System Events" |
| 579 | activate |
| 580 | display alert "Error:フォルダに書き込み権限がありません" |
| 581 | end tell |
| 582 | |
| 583 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 584 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
| 585 | set ocidSaveFilePathURL to (ocidDesktopDirPathURL's URLByAppendingPathComponent:("ファイルリスト.html") isDirectory:(false)) |
| 586 | set listDone to (ocidXMLString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)) |
| 587 | |
| 588 | end if |
| 589 | |
| 590 | set ocidSaveFilePath to ocidSaveFilePathURL's |path|() |
| 591 | set ocidContainerDirPathURL to ocidSaveFilePathURL's URLByDeletingLastPathComponent() |
| 592 | set ocidContainerDirPath to ocidContainerDirPathURL's |path|() |
| 593 | |
| 594 | |
| 595 | ############################## |
| 596 | #ブラウザで開く |
| 597 | |
| 598 | set strAppPath to ("/Applications/Safari.app") as text |
| 599 | set ocidAppPathStr to (refMe's NSString's stringWithString:(strAppPath)) |
| 600 | set ocidAppPath to ocidAppPathStr's stringByStandardizingPath() |
| 601 | set ocidAppPathURL to (refMe's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false)) |
| 602 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 603 | set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration |
| 604 | (ocidConfig's setActivates:(refMe's NSNumber's numberWithBool:true)) |
| 605 | (ocidConfig's setHides:(refMe's NSNumber's numberWithBool:false)) |
| 606 | ## |
| 607 | set ocidOpenURLsArray to refMe's NSMutableArray's alloc()'s init() |
| 608 | (ocidOpenURLsArray's addObject:(ocidSaveFilePathURL)) |
| 609 | ## |
| 610 | (appSharedWorkspace's openURLs:(ocidOpenURLsArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidConfig) completionHandler:(missing value)) |
| 611 | |
| 612 | |
| 613 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 614 | set boolDone to (appSharedWorkspace's selectFile:(ocidSaveFilePath) inFileViewerRootedAtPath:(ocidContainerDirPath)) |
| 615 | (* |
| 616 | set boolDone to (appSharedWorkspace's openURL:(ocidSaveFilePathURL)) |
| 617 | if (boolDone as boolean) is false then |
| 618 | #ファイルを開く |
| 619 | set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias |
| 620 | tell application "Finder" |
| 621 | open file aliasSaveFilePath |
| 622 | end tell |
| 623 | end if |
| 624 | *) |
| 625 | end repeat |
| 626 | |
| 627 | ##処理終了 |
| 628 | return true |
| 629 | end doMakeHTML |
| 630 | |
| 631 | ############################## |
| 632 | # 小数点以下2桁処理 |
| 633 | ############################## |
| 634 | |
| 635 | to doRound2Dec(argNumber) |
| 636 | set strDecNo to ((round (argNumber * 100)) / 100) as text |
| 637 | return strDecNo |
| 638 | end doRound2Dec |
| 639 | ############################## |
| 640 | # 基本的なHTMLの構造 |
| 641 | ############################## |
| 642 | to doMakeRootElement() |
| 643 | # |
| 644 | set ocidRootElement to refMe's NSXMLElement's elementWithName:("html") |
| 645 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja") |
| 646 | ocidRootElement's addAttribute:(ocidAddNode) |
| 647 | # |
| 648 | set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head") |
| 649 | # |
| 650 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("title") |
| 651 | ocidAddElement's setStringValue:("ファイル一覧") |
| 652 | ocidHeadElement's addChild:(ocidAddElement) |
| 653 | # http-equiv |
| 654 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
| 655 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type") |
| 656 | ocidAddElement's addAttribute:(ocidAddNode) |
| 657 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8") |
| 658 | ocidAddElement's addAttribute:(ocidAddNode) |
| 659 | ocidHeadElement's addChild:(ocidAddElement) |
| 660 | # |
| 661 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
| 662 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type") |
| 663 | ocidAddElement's addAttribute:(ocidAddNode) |
| 664 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css") |
| 665 | ocidAddElement's addAttribute:(ocidAddNode) |
| 666 | #ocidHeadElement's addChild:(ocidAddElement) |
| 667 | # |
| 668 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
| 669 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type") |
| 670 | ocidAddElement's addAttribute:(ocidAddNode) |
| 671 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript") |
| 672 | ocidAddElement's addAttribute:(ocidAddNode) |
| 673 | # ocidHeadElement's addChild:(ocidAddElement) |
| 674 | # |
| 675 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
| 676 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport") |
| 677 | ocidAddElement's addAttribute:(ocidAddNode) |
| 678 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720") |
| 679 | ocidAddElement's addAttribute:(ocidAddNode) |
| 680 | ocidHeadElement's addChild:(ocidAddElement) |
| 681 | # |
| 682 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("style") |
| 683 | ocidAddElement's setStringValue:("body {margin: 2rem;background-color: #FFFFFF;font-family: system-ui, -apple-system, sans-serif;}table {width: 100%;max-width: 1000px;border-spacing: 0;border-collapse: separate;caption-side: top;font-family: system-ui, -apple-system, sans-serif;overflow: hidden;box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);}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 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;}tbody tr:hover {background-color: #f1f5f9;transition: background-color 0.2s ease;}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 td a {color: #2563eb;text-decoration: none;font-weight: 500;transition: all 0.2s ease;position: relative;}tbody td a:hover {color: #1d4ed8;background-color: #eff6ff;text-decoration: underline;text-underline-offset: 4px;}.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}}.body_footer a {color: #2563eb;text-decoration: none;font-weight: 500;transition: all 0.2s ease;position: relative;}") |
| 684 | ocidHeadElement's addChild:(ocidAddElement) |
| 685 | # |
| 686 | ocidRootElement's addChild:(ocidHeadElement) |
| 687 | # |
| 688 | return ocidRootElement |
| 689 | end doMakeRootElement |
| 690 | |
| 691 | |
| 692 | |
| 693 | ################################## |
| 694 | #日付 |
| 695 | to doGetDateNo(argDate) |
| 696 | #日付のフォーマットを定義 |
| 697 | set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init() |
| 698 | ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX") |
| 699 | ocidNSDateFormatter's setDateFormat:("yyyyMMdd hhmmss") |
| 700 | set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(argDate) |
| 701 | set strDateAndTime to ocidDateAndTime as text |
| 702 | return strDateAndTime |
| 703 | end doGetDateNo |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | to doGetDateNoString(argFormatStrings) |
| 709 | ####日付情報の取得 |
| 710 | set ocidDate to refMe's NSDate's |date|() |
| 711 | ###日付のフォーマットを定義 |
| 712 | set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init() |
| 713 | ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX") |
| 714 | ocidNSDateFormatter's setDateFormat:(argFormatStrings) |
| 715 | set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate) |
| 716 | set strDateAndTime to ocidDateAndTime as text |
| 717 | return strDateAndTime |
| 718 | end doGetDateNoString |
| 719 | |
| 720 | ################################## |
| 721 | #com.apple.automator.xpc.runnerの終了 |
| 722 | to doQuitAutomatorRunner() |
| 723 | #terminateAutomaticallyTerminableApplications 自動終了 |
| 724 | refMe's NSRunningApplication's terminateAutomaticallyTerminableApplications() |
| 725 | set listBundleID to {"com.apple.automator.xpc.runner", "com.apple.automator.xpc.workflowServiceRunner"} as list |
| 726 | repeat with itemBundleID in listBundleID |
| 727 | set boolDone to false as boolean |
| 728 | #バンドルIDでRunApp取得して |
| 729 | set ocidAppArray to (refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:(itemBundleID)) |
| 730 | repeat with itemApp in ocidAppArray |
| 731 | #まずはソフトに終了させる |
| 732 | set boolDone to itemApp's terminate() |
| 733 | end repeat |
| 734 | end repeat |
| 735 | #terminateAutomaticallyTerminableApplications 自動終了 |
| 736 | refMe's NSRunningApplication's terminateAutomaticallyTerminableApplications() |
| 737 | return true |
| 738 | end doQuitAutomatorRunner |
| 739 | |
| AppleScriptで生成しました | |
