I got this script from another post here which uses safari tools. http://www.macscripter.net/scriptbuilders/category.php?id=1731
The script runs but does not delete the kbid cookies which are set on my site.
Does anybody have a clue why? Following the script below I have the event log of what is going on.
--> use here the propper location
set sfriLibrary to (load script alias "Macintosh HD:Users:dishusa:Desktop:sfri Library.scpt")
--> open dishusa.com for testing purposes
tell application "Safari" to make new document with properties {URL:"http://www.dishusa.com/"}
display dialog "Now, I'm going to search for the cookies sent by dishusa.com." & return & return & ¬
"Please, wait while the page loads..." with icon note
tell sfriLibrary
set awcookies to currentcookies()
set cookiesDisplay to "These are the cookies sent by Dishusa.com:" & return & return
repeat with i in awcookies
set cookiesDisplay to cookiesDisplay & i's cookiename & ":" & i's cookievalue & return
end repeat
set cookiesDisplay to cookiesDisplay & return & "Should I delete them?"
display dialog cookiesDisplay with icon note
--> go ahead, delete cookies using a past expiration date
set x to (current date) - 1 * days
repeat with i in awcookies
sendcookie(i's cookiename, i's cookievalue, x)
end repeat
set awcookies to currentcookies()
if awcookies = {} then
display dialog "Done!" with icon 1
else
display dialog "There was some problem resetting cookies..." with icon 0
end if
end tell
Even Log ( I left out the long load of sfri Library.scpt.
tell application "Safari"
make new document with properties {URL:"http://www.dishusa.com/"}
document "Loading “http://www.dishusa.com/”"
end tell
tell current application
display dialog "Now, I'm going to search for the cookies sent by MacScripter.net
Please, wait while the page loads..." with icon note
{button returned:"OK"}
end tell
tell application "Safari"
do JavaScript "unescape(document.cookie)" in document 1
"kbid=1001; kbid=1001"
display dialog "These are the cookies sent by MacScripter.net:
kbid:1001
kbid:1001
Should I delete them?" with icon note
{button returned:"OK"}
current date
date "Saturday, March 5, 2005 6:21:14 PM"
do JavaScript "function setCookie(n, v, e, p, d, s) {
var curCookie = n + '=' + escape(v) +
((e) ? '; expires=' + e.toGMTString() : '') +
((p) ? '; path=' + p : '') +
((d) ? '; domain=' + d : '') +
((s) ? '; secure' : '');
document.cookie = curCookie;
}
d=new Date(2005,01,28,6,21,14 PM);
setCookie('kbid','1001',d,false,false,false)" in document 1
""
do JavaScript "function setCookie(n, v, e, p, d, s) {
var curCookie = n + '=' + escape(v) +
((e) ? '; expires=' + e.toGMTString() : '') +
((p) ? '; path=' + p : '') +
((d) ? '; domain=' + d : '') +
((s) ? '; secure' : '');
document.cookie = curCookie;
}
d=new Date(2005,01,28,6,21,14 PM);
setCookie('kbid','1001',d,false,false,false)" in document 1
""
do JavaScript "unescape(document.cookie)" in document 1
"kbid=1001; kbid=1001"
display dialog "There was some problem resetting cookies..." with icon 0
{button returned:"OK"}
end tell