不可視ファイルを削除する
ローカルディスク上のフォルダを選択した場合
↓
findコマンドを使って削除する
リムーバブルディスクの場合
↓
dot_cleanコマンドを使って削除します。
ftpを使ってマルっとアップロードする時用
--dot_clean.scpt
(*
不可視ファイルを削除する
選択したディレクトリが『リムーバブル』なら
dot_cleanでクリーニングする
選択したディレクトリがローカルの場合は
findを使って削除する
*)
on run
---プロンプトの文言改行が使えます\nを入れます
set theWithPrompt to "『.』ドットからはじまるリソースファイルを削除します"
---ファイル選択ダイアログのデフォルトのディレクトリ
set theDefLoc to POSIX file "/Volumes"
---ダイアログを出して選択されたファイルは「open」に渡す
open (choose folder default location theDefLoc ¬
with prompt theWithPrompt ¬
invisibles true ¬
with multiple selections allowed without showing package contents)
end run
on open objOpenPath
---リストから読み込む順番の初期化
set numCntList to 1 as number
---繰り返し回数の初期化
set numCntRepeat to 0 as number
---リストの項目数を数える
set numCntRepeat to (count of objOpenPath) as number
---リピートの開始
repeat numCntRepeat times
---順番に読み込む
set theReadTextFileLine to (item numCntList of objOpenPath) as text
---openからの返り値をUNIXパスに変換
set theOpenPath to POSIX path of theReadTextFileLine as text
---区切り文字を指定して
set AppleScript's text item delimiters to ":"
---パスをリストに格納します
set listObjPath to text items of theReadTextFileLine
---区切り文字は戻しておきます
set AppleScript's text item delimiters to ""
---パスの最初の文字=ディスクの名前を取得しておきます
set theObjPathDiskName to (item 1 of listObjPath) as text
---そのディスクが取り外し可能か?ローカルか?を判定
tell application "Finder"
set theEjectableDiskName to (get name of disks whose local volume = true and ejectable = true) as text
end tell
---ローカルディスク|リームーバブルならdot_cleanを使う
if theEjectableDiskName contains theObjPathDiskName then
---コマンドをテキストで整形
set theCmdCom to ("dot_clean -m \"" & theOpenPath & "\"") as text
---コマンドを実行
try
do shell script theCmdCom
end try
log "Done dot_clean"
else
---ネットワークボリュームや排出出来ない(起動ディスク)ボリュームの場合はFindを使う
---TemporaryItemsフォルダを削除
set theCmdCom to ("find \"" & theOpenPath & "\" -name \".TemporaryItems\" -depth -exec rm -Rf {} \\;") as text
try
do shell script theCmdCom
end try
---DS_Store削除
set theCmdCom to ("find \"" & theOpenPath & "\" -name \".DS_Store\" -depth -exec rm {} \\;") as text
try
do shell script theCmdCom
end try
---localized削除
set theCmdCom to ("find \"" & theOpenPath & "\" -name \".localized\" -depth -exec rm {} \\;") as text
try
do shell script theCmdCom
end try
---Thumbs.db削除
set theCmdCom to ("find \"" & theOpenPath & "\" -name \"Thumbs.db\" -depth -exec rm {} \\;") as text
try
do shell script theCmdCom
end try
---Desktop.ini削除
set theCmdCom to ("find \"" & theOpenPath & "\" -name \"Desktop.ini\" -depth -exec rm {} \\;") as text
try
do shell script theCmdCom
end try
---Bridgeのキャッシュ削除
set theCmdCom to ("find \"" & theOpenPath & "\" -name \".BridgeSort\" -depth -exec rm {} \\;") as text
try
do shell script theCmdCom
end try
---Bridgeのキャッシュ削除
set theCmdCom to ("find \"" & theOpenPath & "\" -name \".BridgeLabelsAndRatings\" -depth -exec rm {} \\;") as text
try
do shell script theCmdCom
end try
---分割されたリソースフォークファイルを削除
set theCmdCom to ("find \"" & theOpenPath & "\" -name \"._*\" -depth -exec rm {} \\;") as text
try
do shell script theCmdCom
end try
log "Done Find"
end if
---読み込み順をカウントアップ
set numCntList to numCntList + 1 as number
end repeat
end open
| 固定リンク
「AppleScript」カテゴリの記事
- 濁音 半濁音 置換用レコード(2023.08.21)
- [AppleScript]キーノートの書類サイズを指定して作成(2022.01.09)
- [awk]行頭のスペースを削除する(subで置き換え)(2021.11.16)
- [SpotLight]選択範囲でSpotLight検索(2021.11.03)
- [AppleScript]リソースフォーク(カスタムアイコン)削除(2021.10.12)


[RSS]