ドラック&ドロップしたフォルダ内の隠しファイルを消去する [AppleScript辞書はつくれるか?]
(* A)エディターから実行 *) tell application "Finder" set add to POSIX path of (selection as text) end tell
set ans to my kakurefairusyoukyo(add) ans
(* B)ドロップレット *) on open DropItem set LF to ASCII character 10 set logText to "" repeat with obj in DropItem set add to POSIX path of (obj as string) set ans to my kakurefairusyoukyo(add) set logText to logText & ans & LF end repeat if logText contains ":" then set logText to "( " & ((current date) as string) & " )" & LF & "--------------------" & LF & logText & "--------------------" & LF else set logText to "( " & ((current date) as string) & " )" & LF & " (消去するファイルはありませんでした)" & LF & "--------------------" & LF end if
(* 消去したファイルのログをホームフォルダの書類フォルダ(/user/[LoginUserName]/documents/)にログテキストkillLog.txtを残します *) set logMode to 1 --(0 or 1 or 2) if logMode = 0 then --kill Logを残さない else if logMode = 1 then --kill Logは最新だけ残す(毎回上書き) do shell script ("echo \"" & logText & "\" > $HOME/Documents/killLog.txt ;") else if logMode = 2 then --kill Logは以前の履歴も全て残す(常に後ろに加えていく) do shell script ("echo \"" & logText & "\" >> $HOME/Documents/killLog.txt ;") end if end open
(* 消去の実行部分 *) on kakurefairusyoukyo(add) set theLog to "" --システムおよびデスクトップは除外 set hanteiList to do shell script "ls '" & add & "' ;" if (hanteiList contains "System") and (hanteiList contains "Library") then return false if (add ends with "Desktop") or (add ends with "Desktop:") or (add ends with "Desktop/") then return false
try set aList to do shell script ("du -a '" & add & "' | cut -f2- | sort; ") log aList on error return false end try repeat with oneLine in (every paragraph of aList) set oneLine to oneLine as string if not (oneLine contains ".app/") then --アプリケーションフォルダ内は除外 if (oneLine contains "/._") or (oneLine contains ".DS_Store") or (oneLine contains "Thumbs.db") then try do shell script ("rmdir '" & oneLine & "' ;") set theLog to theLog & "Kill : " & oneLine & (ASCII character 10) on error try do shell script ("rm '" & oneLine & "' ;") set theLog to theLog & "Kill : " & oneLine & (ASCII character 10) on error set theLog to theLog & "Err : " & oneLine & (ASCII character 10) end try end try end if end if end repeat return theLog end kakurefairusyoukyo |
コメント 0