メタル(com.apple.metal)のキャッシュをゴミ箱に入れる
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | #com.cocolog-nifty.quicktimer.icefloe |
004 | # /var/folders/XXX/XXX/Cは主にメタルのキャッシュなので |
005 | # 表示がおかしくなった時のみ有効 それ以外の場合はこの処理は不要 |
006 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
007 | use AppleScript version "2.8" |
008 | use framework "Foundation" |
009 | use framework "AppKit" |
010 | use framework "UniformTypeIdentifiers" |
011 | use scripting additions |
012 | property refMe : a reference to current application |
013 | |
014 | #対象の検索語句 |
015 | #この語句にマッチしたキャッシュをゴミ箱に入れます |
016 | set strSearchkey to ("com.blackmagic") as text |
017 | |
018 | #T テンポラリーディレクトリ |
019 | set appFileManager to refMe's NSFileManager's defaultManager() |
020 | set ocidTempDirURL to appFileManager's temporaryDirectory() |
021 | set ocidContainerDirPathURL to ocidTempDirURL's URLByDeletingLastPathComponent() |
022 | #C キャッシュディレクトリ |
023 | set strDirName to "C" as text |
024 | set ocidCdirPathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(strDirName) isDirectory:(true) |
025 | #コンテンツの収集 |
026 | set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles) |
027 | set ocidKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
028 | #####収集するキー |
029 | ocidKeyArray's addObject:(refMe's NSURLPathKey) |
030 | ocidKeyArray's addObject:(refMe's NSURLContentModificationDateKey) |
031 | set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidCdirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error| :(reference)) |
032 | if (item 2 of listResponse) = (missing value) then |
033 | set ocidFilePathURLArray to (item 1 of listResponse) |
034 | else if (item 2 of listResponse) ≠ (missing value) then |
035 | set strErrorNO to (item 2 of listResponse)'s code() as text |
036 | set strErrorMes to (item 2 of listResponse)'s localizedDescription() as text |
037 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
038 | return "エラーしました" & strErrorNO & strErrorMes |
039 | end if |
040 | #パスのソート |
041 | set ocidDescriptorsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
042 | set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("absoluteString") ascending:(no) selector:("localizedStandardCompare:") |
043 | ocidDescriptorsArray's addObject:(ocidDescriptor) |
044 | set ocidSortedURLArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorsArray) |
045 | #リソース格納用のArray |
046 | set ocidResourceArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
047 | #全てのパスURLを順番に |
048 | repeat with itemSortedURLArray in ocidSortedURLArray |
049 | #リソースキーをDictで取得して |
050 | set listResponse to (itemSortedURLArray's resourceValuesForKeys:(ocidKeyArray) |error| :(reference)) |
051 | set ocidResourceValues to (item 1 of listResponse) |
052 | #Arrayに順に格納していく |
053 | (ocidResourceArray's addObject:(ocidResourceValues)) |
054 | end repeat |
055 | #ソートの定義(ファイル更新日順) |
056 | set ocidDescriptorsArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
057 | set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:(refMe's NSURLLocalizedTypeDescriptionKey) ascending:(yes) selector:("localizedStandardCompare:") |
058 | ocidDescriptorsArray's addObject:(ocidDescriptor) |
059 | set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:(refMe's NSURLContentModificationDateKey) ascending:(no) |
060 | ocidDescriptorsArray's addObject:(ocidDescriptor) |
061 | #ファイルの修正日でソート |
062 | set ocidSortedResourceArray to ocidResourceArray's sortedArrayUsingDescriptors:(ocidDescriptorsArray) |
063 | #並び変わった日付順のパス |
064 | repeat with itemSortedURLArray in ocidSortedResourceArray |
065 | set strFilePath to (itemSortedURLArray's valueForKey:("_NSURLPathKey")) as text |
066 | set dateModDate to (itemSortedURLArray's valueForKey:("NSURLContentModificationDateKey")) as date |
067 | if strFilePath contains strSearchkey then |
068 | #NSURLにして |
069 | set ocidGoToTrashURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(itemSortedURLArray's valueForKey:("_NSURLPathKey")) isDirectory:true) |
070 | #ゴミ箱へ入れる |
071 | set ListDone to (appFileManager's trashItemAtURL:(ocidGoToTrashURL) resultingItemURL:(ocidGoToTrashURL) |error| :(reference)) |
072 | if (item 2 of ListDone) ≠ (missing value) then |
073 | set strErrorNO to (item 2 of ListDone)'s code() as text |
074 | set strErrorMes to (item 2 of ListDone)'s localizedDescription() as text |
075 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
076 | return "エラーしました" & strErrorNO & strErrorMes |
077 | end if |
078 | |
079 | end if |
080 | end repeat |
081 | |
082 | |
083 | |
084 | |
085 | |
086 | |
AppleScriptで生成しました |
| 固定リンク
「Admin Maintenance」カテゴリの記事
- [メンテナンス]ユーザーログファイルをゴミ箱に入れる(2024.11.30)
- [XProtect]アップデート macOS15.1.1(2024.11.20)
- [メンテナンス] Containers以下サンドボックスアプリのキャッシュを全部ゴミ箱に入れる(2024.11.09)
- [メンテナンス]Thumbs.dbやDS_Store等をゴミ箱に移動させる(2024.11.09)