First off I would like to applogize. It has been years since I have used AppleScript and now it has become COMPLETLY forgin to me. I need help.
This is the problem, I want to make an application (or service) that always runs that does stuff when Safari triggers an event.
The psudo code goes as follows.
on event Safari ‘refresh’ button is clicked then
delete all files in the internet cache
end event
That is it and I have been racking my brain trying to figure out how to do that in apple script. I am sure that there is a way. Any insite or code that might make this application work would be awsome (BTW I am sorry about being such a nOOb).
Hello TKOTC,
I just did a search for the word “Safari” on this site and came up with some 125 threads, including the following which should get you started:
http://bbs.applescript.net/viewtopic.php?t=6689&highlight=safari
I hope this helps.
Sincerely,
Variable as the shade
You can’t do this directly.
In order to do this, Safari would need to support hooks to call your script based on user actions. This is entirely possible to do from AppleScript’s perspective, but it requires the program to be written to support script attaching, which it doesn’t.
Therefore you can not tell when the user clicks a button. The closest you can get is to periodically poll the application to see if the URL has changed (as described in the above link), but it will be hard to detect refreshes.
Or you can instruct the user to ignore the “reload” button and use instead a script similar to this one:
--> empty cache files
do shell script "cd ~/Library/Caches/Safari; rm -r *"
--> reload frontmost page
tell application "Safari" to ¬
set URL of document 1 to URL of document 1