【分享】用Automator製作系統維護程式

相信很多人都有下載OnyX來維護您的系統,但是我看到蠻多使用者在用OnyX都會出現一些問題,
這些維護程式都是OSX作業系統所提供的,如果您熟悉終端機模式,也可以藉由command來達到
相同的功能。
我將我所知道的指令用Automator來做成一個小程式,藉此讓您了解OnyX所做的一些功能。

每個功能及所對應的終端機指令:
1.Periodic Cleanup : sudo periodic daily weekly monthly
2.Clear Cache Files :
sudo rm -f -PR ~/Library/Caches/*
sudo rm -f -PR /Library/Caches/*
sudo rm -f -PR /System/Library/Caches/*

3.Verify Preference Files : sudo plutil ~/Library/Preferences/*.plist
4.Repair Permissions : sudo diskutil repairPermissions
5.Update Prebindings : sudo update_prebinding -root
6.Update Locate Database : sudo /usr/libexec/locate.updatedb
7.Update Whatis Database : sudo /usr/libexec/makewhatis -v

結果將儲存在桌面的 Log.txt 檔案

流程圖如下:
【分享】用Automator製作系統維護程式

將下面AplleScript程式碼copy到Automator的執行AppleScript欄位中:
【分享】用Automator製作系統維護程式

AppleScript程式碼:
set DIALOG01 to "Periodic Cleanup:定期清理(每日,每週,每月)?"
set DIALOG02 to "Clear Cache Files:清理快取?"
set DIALOG03 to "Verify Preference Files:驗證偏好檔案?"
set DIALOG04 to "Repair Permissions:驗證權限?"
set DIALOG05 to "Update Prebindings:更新軟體套件連結?"
set DIALOG06 to "Update Locate Database:更新資料庫?"
set DIALOG07 to "Update Whatis Database:更新Whatis資料庫?"

--Periodic Cleanup
display dialog DIALOG01 buttons {"跳過", "執行"} default button 2 with icon 0
set the button_pressed to the button returned of the result
if the button_pressed is "執行" then
do shell script "sudo periodic daily weekly monthly >> ~/Desktop/Log.txt" with administrator privileges

do shell script "sudo echo ----- Periodic Cleanup Finish :`date`>>~/Desktop/Log.txt" with administrator privileges
end if

--Clear Cache Files
display dialog DIALOG02 buttons {"跳過", "執行"} default button 2 with icon 0
set the button_pressed to the button returned of the result
if the button_pressed is "執行" then
do shell script "sudo rm -f -PR ~/Library/Caches/* >> ~/Desktop/Log.txt;sudo rm -f -PR /Library/Caches/* >> ~/Desktop/Log.txt;sudo rm -f -PR /System/Library/Caches/* >> ~/Desktop/Log.txt" with administrator privileges

do shell script "sudo echo ----- Clear Cache Finish :`date`>>~/Desktop/Log.txt" with administrator privileges
end if

--Verify Preference Files
display dialog DIALOG03 buttons {"跳過", "執行"} default button 2 with icon 0
set the button_pressed to the button returned of the result
if the button_pressed is "執行" then
do shell script "sudo plutil ~/Library/Preferences/*.plist>>~/Desktop/Log.txt" with administrator privileges

do shell script "sudo echo ----- Verify Preference Files Finish :`date`>>~/Desktop/Log.txt" with administrator privileges
end if

--Repair Permissions
display dialog DIALOG04 buttons {"跳過", "執行"} default button 2 with icon 0
set the button_pressed to the button returned of the result
if the button_pressed is "執行" then
do shell script "sudo diskutil repairPermissions / >> ~/Desktop/Log.txt" with administrator privileges

do shell script "sudo echo ----- Repair Permissions Finish :`date`>>~/Desktop/Log.txt" with administrator privileges

end if

--Update Prebindings
display dialog DIALOG05 buttons {"跳過", "執行"} default button 2 with icon 0
set the button_pressed to the button returned of the result
if the button_pressed is "執行" then
do shell script "sudo update_prebinding -root / >> ~/Desktop/Log.txt" with administrator privileges

do shell script "sudo echo ----- Update Prebindings Finish :`date`>>~/Desktop/Log.txt" with administrator privileges

end if

--Update Locate Database
display dialog DIALOG06 buttons {"跳過", "執行"} default button 2 with icon 0
set the button_pressed to the button returned of the result
if the button_pressed is "執行" then
do shell script "sudo /usr/libexec/locate.updatedb >> ~/Desktop/Log.txt" with administrator privileges

do shell script "sudo echo ----- Update Locate Database Finish :`date`>>~/Desktop/Log.txt" with administrator privileges

end if

--Update Whatis Database
display dialog DIALOG07 buttons {"跳過", "執行"} default button 2 with icon 0
set the button_pressed to the button returned of the result
if the button_pressed is "執行" then
do shell script "sudo /usr/libexec/makewhatis -v; >> ~/Desktop/Log.txt" with administrator privileges

do shell script "sudo echo ----- Update Whatis Database Finish :`date`>>~/Desktop/Log.txt" with administrator privileges

end if

將貼上後,按鐵鎚一下(compiler),看是否有錯誤!
【分享】用Automator製作系統維護程式
正確的話,將Automator儲存成應用程式。
執行畫面:
【分享】用Automator製作系統維護程式
【分享】用Automator製作系統維護程式

在定期清理(每月),驗證權限,會比較花時間,需要等一下!

輸出Log.txt檔案內容:
【分享】用Automator製作系統維護程式
太厲害了,馬上把這一篇文章收藏起來。

很實用的東西謝謝。


想請問一下 更新軟體套件連結<----這一個的作用是??
serffnt wrote:
太厲害了,馬上把這一...(恕刪)

Updating the Prebinding:這個我不太會翻譯,所以我根據 O'Reilly原文翻成"軟體套件連結",
我簡單的說:
就是強制OSX去go through 一下,所有的應用程式檔案,以確定所有的連結是否正確!
你在更新OSX的程式,完成的時候會有系統最佳化的訊息,就包含這個動作.

或是用$man update_prebinding來查詢說明文件.
請問檢查之後出現這個視窗是哪裡有問題嗎?
你有改過 程式碼嗎,或是沒有COPY 完全 ,因為我使用上是正常的。

謝謝版大的解說。那我大概了解了。還有這一篇分享真的不錯用。謝謝
麥克雞塊 wrote:
請問檢查之後出現這個...(恕刪)


這個程式共有7個小段,你可以一段一段copy,編譯,
例如第一段:

set DIALOG01 to "Periodic Cleanup:定期清理(每日,每週,每月)?"
--Periodic Cleanup
display dialog DIALOG01 buttons {"跳過", "執行"} default button 2 with icon 0
set the button_pressed to the button returned of the result
if the button_pressed is "執行" then
do shell script "sudo periodic daily weekly monthly >> ~/Desktop/Log.txt" with administrator privileges

do shell script "sudo echo ----- Periodic Cleanup Finish :`date`>>~/Desktop/Log.txt" with administrator privileges
end if

JK.Chang wrote:
將Automator儲存成應用程式(恕刪)


不好意思!請問要怎麼存成應用程式呢?
我按照步驟執行,
可是看到將Automator儲存成應用程式,愣住了!
是直接由編輯到儲存為...嗎?
(如果問了蠢問題請見諒,我是真的不知道!)

還有一點就是,她執行的時候會一值要我輸入密碼耶!
這是正常的嗎?

Automator我不熟,自己本身的理解能力亦不佳
書中談到Automator這一塊也不多!還請大大不嫌棄指教!



謝謝您無私的po文帶領我們進入水果幫!

真的是太厲害了 可是身為菜鳥的我完全不敢動手 我怕死 我承認了
straw090 wrote:
是直接由編輯到儲存為...嗎?(恕刪)

是的,直接存成應用程式,即可!

critina1020 wrote:
我怕死 我承認了(恕刪)

說實在的,我剛開始做,也很怕,讓我擔心是下面這3項:
1.更新軟體套件連結?
2.更新資料庫?
3.更新Whatis資料庫?
因為我不知道用途?但是做完後,你會發現開機速度變快了!

文章分享
評分
評分
複製連結

今日熱門文章 網友點擊推薦!