Gettting Safari to clear cache via AS.

I have been trying to figuar out a way to script Safari to clear it’s cache. I’ve talked to a couple of people that said that I could do it via the menu items but can not figuar out how. I have even tried to record my actions as I clear the cache to no avail. can someone help with this? Thanks

Hi,

you can either remove the cache of Safari permanently by
deleting the folder ~/Library/Caches/Safari manually and then creating a zero byte file in the
Terminal or with this script:

do shell script "touch ~/Library/Caches/Safari"

or clear Safari’s cache with this shell script without deleting the parent folder:

do shell script "rm -rf ~/Library/Caches/Safari/*"

I used to use ui scripting to do this:


tell application "Safari" to activate
tell application "System Events"
	tell process "Safari"
		keystroke "e" using {command down, option down}
		keystroke return
	end tell
end tell

ui scripting:

http://www.apple.com/applescript/uiscripting/01.html

Afterwards you can add clearing the history.

Sometimes it didn’t work. I think it was when the focus of the browser is in a text field or something. In that case you need to change the focus of keystrokes.

gl,

Thanks
Both suggestions worked