« PDF 指定ページを削除 | トップページ | OneDriveバージョンチェッカv3 »

Containersクリーナー


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

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
(*
com.cocolog-nifty.quicktimer.icefloe
Containersの全フォルダ対象で
Caches
Application Scripts
HTTPStorages
Saved Application State
Logs
の内包物をゴミ箱に入れます
*)
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions

property refMe : a reference to current application

property refNSNotFound : a reference to 9.22337203685477E+18 + 5807
set ocidFalse to (refMe's NSNumber's numberWithBool:false)
set ocidTrue to (refMe's NSNumber's numberWithBool:true)

set appFileManager to refMe's NSFileManager's defaultManager()
set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask))
set ocidLibraryDirPathURL to ocidURLsArray's firstObject()
##################################
###Logs 
set ocidTargetDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Logs")
##プロパティ
set ocidPropertieKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidPropertieKeyArray's addObject:(refMe's NSURLPathKey)
ocidPropertieKeyArray's addObject:(refMe's NSURLIsDirectoryKey)
##オプション(隠しファイルは含まない)
set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles
####ディレクトリのコンテツを収集
set ocidEnuDict to (appFileManager's enumeratorAtURL:(ocidTargetDirPathURL) includingPropertiesForKeys:(ocidPropertieKeyArray) options:(ocidOption) errorHandler:(reference))
repeat
  set ocidEnuURL to ocidEnuDict's nextObject()
  if ocidEnuURL = (missing value) then
    exit repeat
  else
    set listResult to (ocidEnuURL's getResourceValue:(reference) forKey:(refMe's NSURLIsRegularFileKey) |error|:(reference))
    set boolIsValue to (item 2 of listResult)
    ##ファイルならゴミ箱にここはファイルのみ削除する(どうせまたできるからね)
    if boolIsValue = ocidTrue then
      set listDone to (appFileManager's trashItemAtURL:(ocidEnuURL) resultingItemURL:(ocidEnuURL) |error|:(reference))
      if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedDescription() as text
      end if
    end if
  end if
end repeat


##################################
###Containersクリーナー
set ocidTargetDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Containers")
##################################
###URLを格納するリスト
set ocidFilePathURLAllArray to (refMe's NSMutableArray's alloc()'s initWithCapacity:0)
##プロパティ
set ocidPropertieKeyArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0)
ocidPropertieKeyArray's addObject:(refMe's NSURLPathKey)
ocidPropertieKeyArray's addObject:(refMe's NSURLIsDirectoryKey)
##オプション(隠しファイルは含まない)
set ocidOption to refMe's NSDirectoryEnumerationSkipsHiddenFiles
####ディレクトリのコンテツを収集
set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidTargetDirPathURL) includingPropertiesForKeys:(ocidPropertieKeyArray) options:(ocidOption) |error|:(reference))
set ocidURLArray to (item 1 of listResponse)

######Caches
repeat with itemURL in ocidURLArray
  set ocidCachesDirPathURL to (itemURL's URLByAppendingPathComponent:("Data/Library/Caches") isDirectory:(true))
  set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidCachesDirPathURL) includingPropertiesForKeys:(ocidPropertieKeyArray) options:(ocidOption) |error|:(reference))
  set ocidSubURLArray to (item 1 of listResponse)
  if ocidSubURLArray ≠ (missing value) then
    repeat with itemSubURL in ocidSubURLArray
      set listDone to (appFileManager's trashItemAtURL:(itemSubURL) resultingItemURL:(itemSubURL) |error|:(reference))
      if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedDescription() as text
      end if
    end repeat
  end if
end repeat

######tmp
repeat with itemURL in ocidURLArray
  set ocidCachesDirPathURL to (itemURL's URLByAppendingPathComponent:("Data/tmp") isDirectory:(true))
  set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidCachesDirPathURL) includingPropertiesForKeys:(ocidPropertieKeyArray) options:(ocidOption) |error|:(reference))
  set ocidSubURLArray to (item 1 of listResponse)
  if ocidSubURLArray ≠ (missing value) then
    repeat with itemSubURL in ocidSubURLArray
      set listDone to (appFileManager's trashItemAtURL:(itemSubURL) resultingItemURL:(itemSubURL) |error|:(reference))
      if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedDescription() as text
      end if
    end repeat
  end if
end repeat

######log
repeat with itemURL in ocidURLArray
  set ocidCachesDirPathURL to (itemURL's URLByAppendingPathComponent:("Data/Library/Logs") isDirectory:(true))
  set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidCachesDirPathURL) includingPropertiesForKeys:(ocidPropertieKeyArray) options:(ocidOption) |error|:(reference))
  set ocidSubURLArray to (item 1 of listResponse)
  if ocidSubURLArray ≠ (missing value) then
    repeat with itemSubURL in ocidSubURLArray
      set listDone to (appFileManager's trashItemAtURL:(itemSubURL) resultingItemURL:(itemSubURL) |error|:(reference))
      if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedDescription() as text
      end if
    end repeat
  end if
end repeat

######Saved Application State
repeat with itemURL in ocidURLArray
  set ocidCachesDirPathURL to (itemURL's URLByAppendingPathComponent:("Data/Library/Saved Application State") isDirectory:(true))
  set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidCachesDirPathURL) includingPropertiesForKeys:(ocidPropertieKeyArray) options:(ocidOption) |error|:(reference))
  set ocidSubURLArray to (item 1 of listResponse)
  if ocidSubURLArray ≠ (missing value) then
    repeat with itemSubURL in ocidSubURLArray
      set listDone to (appFileManager's trashItemAtURL:(itemSubURL) resultingItemURL:(itemSubURL) |error|:(reference))
      if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedDescription() as text
      end if
    end repeat
  end if
end repeat

######Application Scripts
repeat with itemURL in ocidURLArray
  set ocidCachesDirPathURL to (itemURL's URLByAppendingPathComponent:("Data/Library/Application Scripts") isDirectory:(true))
  set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidCachesDirPathURL) includingPropertiesForKeys:(ocidPropertieKeyArray) options:(ocidOption) |error|:(reference))
  set ocidSubURLArray to (item 1 of listResponse)
  if ocidSubURLArray ≠ (missing value) then
    repeat with itemSubURL in ocidSubURLArray
      set listDone to (appFileManager's trashItemAtURL:(itemSubURL) resultingItemURL:(itemSubURL) |error|:(reference))
      if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedDescription() as text
      end if
    end repeat
  end if
end repeat


######HTTPStorages
repeat with itemURL in ocidURLArray
  set ocidCachesDirPathURL to (itemURL's URLByAppendingPathComponent:("Data/Library/Application Scripts") isDirectory:(true))
  set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidCachesDirPathURL) includingPropertiesForKeys:(ocidPropertieKeyArray) options:(ocidOption) |error|:(reference))
  set ocidSubURLArray to (item 1 of listResponse)
  if ocidSubURLArray ≠ (missing value) then
    repeat with itemSubURL in ocidSubURLArray
      set listDone to (appFileManager's trashItemAtURL:(itemSubURL) resultingItemURL:(itemSubURL) |error|:(reference))
      if (item 2 of listDone) ≠ (missing value) then
log (item 2 of listDone)'s localizedDescription() as text
      end if
    end repeat
  end if
end repeat

|

« PDF 指定ページを削除 | トップページ | OneDriveバージョンチェッカv3 »

Admin Maintenance」カテゴリの記事