on run {} tell application "Finder" try set SafariFolder to folder "Safari" of folder "Library" of home set SafariCache to folder "Caches" of folder "Library" of home set SafariIcons to folder "Icons" of SafariFolder set SafariHistory to file "History.plist" of SafariFolder set SafariDownloads to file "Downloads.plist" of SafariFolder on error errorMessage display alert "An error has occurred." message "Below is the error returned by AppleScript. This may assist you in troubleshooting the issue." & return & return & errorMessage as warning return -- Die on error. end try set SafariIsRunning to (name of every process contains "Safari") delete SafariCache delete SafariIcons delete SafariHistory delete SafariDownloads if SafariIsRunning then tell application "Safari" activate display alert "Safari has now been cleaned up." message "You can now resume the application." as informational giving up after 2 end tell else display alert "Safari has now been cleaned up." message "Changes have already taken effect and will be retained the next time you launch the application." as informational end if end tell end run