Mac OS X 垃圾桶清潔劑
2002/04/02 4:03 pm 白萊恩

今天b上 AppleScript Studio 的訓練課程時,老師 Sal 提到 Mac OS X 下 AppleScript 的 do shell script 指令能以管理員的權限執行 Shell Scripts,所以一時興起就寫了一個可以讓 Mac OS X 使用者把垃圾筒澈底清乾淨的小程式,如果您會用 AppleScript Editor 的話,可以拷貝以下的程式碼來用:

-- The Scrubber 
-- By Bryan Chang, 4/2/2002
-- Runs on Mac OS X 10.1 or later
-- Disclaimer: I am not responsible for any data lost caused directly or indirectly by running this applet!


on run
    set theResult to display dialog "Please enter administrative password." default answer "" default button "OK"
    try
        set myPasswd to text returned of theResult
        set buttonPressed to button returned of theResult
    if buttonPressed is "OK" then
            set myDir to system attribute "HOME"
            do shell script "rm -rf /.Trashes/*" password myPasswd with administrator privileges
            do shell script "rm -rf " & myDir & "/.Trash/*" password myPasswd with administrator privileges
            tell application "Finder" to empty trash -- update the trash can icon
        end if
    on error
        display dialog "We need a password to do the scrubbing, please try again." buttons {"OK"} default button 1
        return
    end try
end run

不懂 AppleScript 的人可以按下相關連結直接下載編譯好的版本。

請注意: 本人對因執行上述軟體所直接或間接造成之損失不負任何責任。