
[システム設定]初期設定フォルダメンテナンス(サードパーティの設定ファイルにラベルをつける)
【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 | /Users/ユーザーID/Library/Preferences |
| 008 | いわゆる『サンドボックス・アプリケーション』のディレクトリで |
| 009 | サードバーティ製品のディレクトリに |
| 010 | 緑のタグを付けることで |
| 011 | |
| 012 | 未使用になったアプリの設定を削除するのを手伝います。 |
| 013 | |
| 014 | サードバーティ製品のリストをダイアログに出します |
| 015 | 選択したフォルダをゴミ箱に入れます |
| 016 | ゴミ箱に入れるには |
| 017 | セキュリティ設定の『フルディスクアクセス』が必要です。 |
| 018 | |
| 019 | 心配な場合は、実行しないでください |
| 020 | |
| 021 | |
| 022 | |
| 023 | com.cocolog-nifty.quicktimer.icefloe *) |
| 024 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 025 | use AppleScript version "2.8" |
| 026 | use framework "Foundation" |
| 027 | use framework "AppKit" |
| 028 | use scripting additions |
| 029 | |
| 030 | property refMe : a reference to current application |
| 031 | |
| 032 | #################################### |
| 033 | #検索語句 設定項目 この語句にマッチしないファイルにラベルを入れる |
| 034 | set strSearchWord to ("apple") as text |
| 035 | #ラベルカラー |
| 036 | set numLabelIndex to 2 as integer |
| 037 | (* |
| 038 | 0:ラベル無し |
| 039 | 1:グレー |
| 040 | 2:グリーン |
| 041 | 3:パープル |
| 042 | 4:ブルー |
| 043 | 5:イエロー |
| 044 | 6:レッド |
| 045 | 7:オレンジ *) |
| 046 | |
| 047 | |
| 048 | |
| 049 | #################################### |
| 050 | #Containers |
| 051 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 052 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 053 | set ocidLibraryDirPathURL to ocidURLsArray's firstObject() |
| 054 | set ocidTargetDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences") isDirectory:(true) |
| 055 | # |
| 056 | set ocidPropertiesForKeys to refMe's NSMutableArray's alloc()'s init() |
| 057 | ocidPropertiesForKeys's addObject:(refMe's NSURLIsRegularFileKey) |
| 058 | ocidPropertiesForKeys's addObject:(refMe's NSURLNameKey) |
| 059 | ocidPropertiesForKeys's addObject:(refMe's NSURLPathKey) |
| 060 | set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles) |
| 061 | #URLの収集 |
| 062 | set listResponse to appFileManager's contentsOfDirectoryAtURL:(ocidTargetDirPathURL) includingPropertiesForKeys:(ocidPropertiesForKeys) options:(ocidOption) |error|:(reference) |
| 063 | set ocidItemURLArray to (item 1 of listResponse) |
| 064 | |
| 065 | #ログ用 |
| 066 | set ocidThirdPartyArray to refMe's NSMutableArray's alloc()'s init() |
| 067 | |
| 068 | ############################## |
| 069 | # サードパーティチェック |
| 070 | #Apple以外のコンテナの場合は グリーンのインデックスをつける |
| 071 | repeat with itemURL in ocidItemURLArray |
| 072 | #フォルダ名が |
| 073 | set strDirName to (itemURL's lastPathComponent()) as text |
| 074 | #Apple |
| 075 | if strDirName contains strSearchWord then |
| 076 | #Appleの設定ファイルには何もしない |
| 077 | else |
| 078 | #サードパティの設定ファイルにラベルを付与 |
| 079 | set ocidLabelNo to (refMe's NSNumber's numberWithInteger:(numLabelIndex)) |
| 080 | set ListDone to (itemURL's setResourceValue:(ocidLabelNo) forKey:(refMe's NSURLLabelNumberKey) |error|:(reference)) |
| 081 | (ocidThirdPartyArray's addObject:(strDirName)) |
| 082 | if (item 1 of ListDone) is true then |
| 083 | else if (item 2 of ListDone) ≠ (missing value) then |
| 084 | set strErrorNO to (item 2 of ListDone)'s code() as text |
| 085 | set strErrorMes to (item 2 of ListDone)'s localizedDescription() as text |
| 086 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 087 | return "エラーしました" & strErrorNO & strErrorMes |
| 088 | end if |
| 089 | end if |
| 090 | end repeat |
| 091 | ############################## |
| 092 | #ダイアログ |
| 093 | set ocidSortedArray to ocidThirdPartyArray's sortedArrayUsingSelector:("localizedStandardCompare:") |
| 094 | set listSortedArray to ocidSortedArray as list |
| 095 | set strTitle to ("選んでください") as text |
| 096 | set strPrompt to ("選んだフォルダをゴミ箱に入れます") as text |
| 097 | set strOK to ("OK") as text |
| 098 | set strCancel to ("キャンセル") as text |
| 099 | try |
| 100 | tell application "System Events" |
| 101 | activate |
| 102 | set listResponse to (choose from list listSortedArray with title strTitle with prompt strPrompt default items (last item of listSortedArray) OK button name strOK cancel button name strCancel with multiple selections allowed without empty selection allowed) as list |
| 103 | end tell |
| 104 | on error strErrMes number numErrNo |
| 105 | tell application "System Events" to quit |
| 106 | log strErrMes & numErrNo |
| 107 | return false |
| 108 | end try |
| 109 | if (first item of listResponse) is false then |
| 110 | tell application "System Events" to quit |
| 111 | error "ユーザによってキャンセルされました。" number -128 |
| 112 | else if (class of listResponse) is list then |
| 113 | if listResponse is {} then |
| 114 | tell application "System Events" to quit |
| 115 | error "Error 何も選んでいません" number -128 |
| 116 | end if |
| 117 | end if |
| 118 | |
| 119 | ############################## |
| 120 | #ゴミ箱に入れる |
| 121 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 122 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 123 | set ocidLibraryDirPathURL to ocidURLsArray's firstObject() |
| 124 | set ocidContainersDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Preferences") isDirectory:(true) |
| 125 | |
| 126 | repeat with itemDirName in listResponse |
| 127 | log itemDirName as text |
| 128 | set ocidTargetDirPathURL to (ocidContainersDirPathURL's URLByAppendingPathComponent:(itemDirName) isDirectory:(true)) |
| 129 | |
| 130 | |
| 131 | set ListDone to (appFileManager's trashItemAtURL:(ocidTargetDirPathURL) resultingItemURL:(ocidTargetDirPathURL) |error|:(reference)) |
| 132 | if (item 2 of ListDone) ≠ (missing value) then |
| 133 | set strErrorNO to (item 2 of ListDone)'s code() as text |
| 134 | set strErrorMes to (item 2 of ListDone)'s localizedDescription() as text |
| 135 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
| 136 | log "エラーしました" & strErrorNO & strErrorMes |
| 137 | end if |
| 138 | |
| 139 | end repeat |
| 140 | |
| 141 | |
| 142 | ############################## |
| 143 | #開く |
| 144 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 145 | set boolDone to appSharedWorkspace's openURL:(ocidContainersDirPathURL) |
| 146 | |
| 147 | #ログ用にテキストを用意して |
| 148 | set ocidJoinText to ocidSortedArray's componentsJoinedByString:(return) |
| 149 | #終了 |
| 150 | return ocidJoinText as text |
| AppleScriptで生成しました | |
