Skip to content

Instantly share code, notes, and snippets.

@mherb
Created September 30, 2012 17:46
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mherb/3807895 to your computer and use it in GitHub Desktop.
Save mherb/3807895 to your computer and use it in GitHub Desktop.
Apple Script to clean Safari Cache, History, Webpage Previews, Local Storage and Databases
-- Can be executed from Terminal using "osascript safari_cache_clean.scpt"
-- inspired by http://www.macuser.de/forum/f30/safari-alle-cache-544226/
set appname to "Safari"
if appIsRunning(appname) then
set started to true
-- Quit App
tell application appname to quit
else
set started to false
end if
-- Remove files
do shell script "rm -f ~/Library/Safari/history.plist"
do shell script "rm -f ~/Library/Safari/HistoryIndex.sk"
do shell script "rm -rf ~/Library/Safari/LocalStorage"
do shell script "rm -rf ~/Library/Safari/Databases"
do shell script "rm -f ~/Library/Caches/com.apple.Safari/Cache.db"
do shell script "rm -rf ~/Library/Caches/com.apple.Safari/Webpage\\ Previews"
do shell script "rm -rf ~/Library/Caches/Metadata/Safari/History"
-- Restart App if it was running before
if started then
tell application appname to activate
end if
-- See http://techblog.willshouse.com/2012/02/21/applescript-check-application-is-running/
on appIsRunning(appname)
tell application "System Events" to (name of processes) contains appname
end appIsRunning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment