Cookies Script to delete cookie

I got this script from a previoius post:
First, it opens my default home page and not the location in the first tell line.

I re-did that line so it does open my proper page, but it does it in a new window. I don’t know how to open a new page without it first opening my default home page.

Second… It does not delete the cookie. Do you know what the problem here is?

--> 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

The previous post needs this to operate. This is the sfri Library.scpt that is on the desktop or you can dowload these tools at the address near the top of the code.

property parent : application "Safari"
property AboutInfo : "sfri Library - Pescados Software, 2004 (bastard son of MSIE Library@2001)" & return & "Visit us at [url=http://www.pescadosweb.com/]http://www.pescadosweb.com/"[/url]
property version : 1.1
(*
--> fixed issue in "writedata"
--> added more examples of sfri Library's usage
--> highly improved "statistics with allinfo"
--> added the "progressBar" script object
--> added focuswin()
--> added extractLinks()
--> added extractImages()
*)

using terms from application "Safari"
	on modifyimage(imgID, attribute, newvalue)
		if class of attribute = list then
			set nat to ""
			repeat with i from 1 to count attribute
				set nv to newvalue's item i
				if class of nv = string then set nv to """ & nv & """
				set nat to nat & (attribute's item i) & "=" & nv & ","
			end repeat
			set attrivalue to (characters 1 thru -2 of nat as text)
		else
			if class of newvalue = string then set newvalue to """ & newvalue & """
			set attrivalue to attribute & "=" & newvalue
		end if
		if imgID = "all" then
			do JavaScript "for (var i=0; i<document.images.length;i++) {with (document.images[i]) {" & attrivalue & "}}" in document 1
		else
			if class of imgID = list then
				set AppleScript's text item delimiters to ","
				set imgID to imgID as text
				set AppleScript's text item delimiters to ""
			else
				set imgID to """ & imgID & """
			end if
			do JavaScript "a = new Array(" & imgID & ");for (var i=0; i<a.length;i++) {w = a[i];with (document.images[w]) {" & attrivalue & "}}" in document 1
		end if
	end modifyimage
	to sendcookie(nombre, valor, caduca)
		set dDay to text -2 thru -1 of ("0" & (day of caduca))
		copy caduca to date2
		set date2's month to January
		set dMonth to text 1 thru 2 of ("0" & (((caduca - date2 + 3944592) div 2629728) - 1))
		set dYear to (year of caduca as string)
		set AppleScript's text item delimiters to ":"
		set {dHours, dMinutes, dSeconds} to text items of (time string of caduca)
		set AppleScript's text item delimiters to {""}
		
		set cookiecode to "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(" & dYear & "," & dMonth & "," & dDay & "," & dHours & "," & dMinutes & "," & dSeconds & ");
setCookie('" & nombre & "','" & valor & "',d,false,false,false)"
		
		do JavaScript cookiecode in document 1
	end sendcookie
	on currentcookies()
		set y to (do JavaScript "unescape(document.cookie)" in document 1)
		set AppleScript's text item delimiters to "; "
		set y to every text item of y
		set Z to {}
		try
			repeat with i in y
				set AppleScript's text item delimiters to "="
				set {a, b} to every text item of i
				set Z to Z & {{cookiename:a} & {cookievalue:b}}
			end repeat
		end try
		set AppleScript's text item delimiters to ""
		Z
	end currentcookies
	on writedata(t)
		do JavaScript "document.open();document.write("" & SearchReplace(""", "\"", t) & "");document.close();" in document 1
	end writedata
	on openwindow given data:{x, y, Z, a}
		try
			set theCode to "myWin = window.open("" & x & "","" & y & "",'" & Z & "');"
			if a ? "" then set theCode to theCode & "myWin.document.open();myWin.document.write('" & a & "');myWin.document.close();"
		on error
			set theCode to "window.open()"
		end try
		do JavaScript theCode in document 1
	end openwindow
	on setcolor(theelement, thecolor)
		do JavaScript "document." & theelement & "Color = "" & thecolor & """ in document 1
		return
	end setcolor
	on getcolor(theelement)
		do JavaScript "document." & theelement & "Color" in document 1
	end getcolor
	script progressBar
		property mainMsg : "Progress..."
		property subMsg : "Processing stuff..."
		property credits : "Progress bar powered by <a href="http://homepage.mac.com/julifos/soft" target="_blank">sfri Library</a>!</div>"
		property currentLength : 0
		property maxLength : 50
		property textColor : "BBBBBB"
		property bgColor : "EEEEEE"
		property linkColor : "027AA2"
		property hoverColor : "FFCC00"
		property barBorderColor : "CCCCCC"
		property barTopColor : "027AA2"
		property barMainColor : "0099CC"
		property barBottomColor : "02B7F2"
		property monitorCode : "<html><style type="text/css"><!--td {font-family: Tahoma, Arial;font-size: 12px;color: #$;}body {background-color: #$;font-family: Tahoma, Arial;font-size: 10px;color: #999999;}a:link {color: #$;text-decoration: none;}a:hover {color: #$;}a:visited {color: #$;}--></style><body><table align="left" cellpadding="0" cellspacing="0"><tr><td><strong>$</strong></td></tr><tr><td>$</td></tr></table><br><br><br><table width="200" height="10" border="1" align="left" cellpadding="0" cellspacing="0" bordercolor="#$"><tr><td><table width="$" height="10" border="0" align="left" cellpadding="0" cellspacing="0"><tr height="2"><td bgcolor="#$"></td></tr><tr><td bgcolor="#$"></td></tr><tr height="4"><td bgcolor="#$"></td></tr></table></td></tr></table><br><hr><div align="right">$</body></html>"
		to endBar()
			close (first document whose URL is "" and source is "")
		end endBar
		to updateBar()
			set currentLength to currentLength + 1
			
			--> create HTML code
			set tablepx to round ((196 * currentLength) / maxLength)
			
			set AppleScript's text item delimiters to "$"
			set progressCode to monitorCode's text items
			set AppleScript's text item delimiters to {""}
			
			set progressCode to progressCode's item 1 & textColor & progressCode's item 2 & bgColor & progressCode's item 3 & linkColor & progressCode's item 4 & hoverColor & progressCode's item 5 & linkColor & progressCode's item 6 & mainMsg & progressCode's item 7 & subMsg & progressCode's item 8 & barBorderColor & progressCode's item 9 & tablepx & progressCode's item 10 & barTopColor & progressCode's item 11 & barMainColor & progressCode's item 12 & barBottomColor & progressCode's item 13 & credits & progressCode's item 14 as text
			
			set zkk to "document.open();document.write('" & progressCode & "');document.close();"
			
			--> print HTML code to progress window
			do JavaScript zkk in (first document whose URL is "" and source is "")
			return
		end updateBar
		to initBar()
			try
				do JavaScript "progWin = window.open('', 'progress', 'toolbar=no, directories=no, location=no, status=no, menubar=no, resizable=no, scrollbars=no, width=500, height=20');" in document 1
			on error
				error "Open a window before running this handler..."
			end try
			set currentLength to 0
			return
		end initBar
		to resetBar()
			set mainMsg to "Progress..."
			set subMsg to "Processing stuff..."
			set credits to "Progress bar powered by <a href="http://homepage.mac.com/julifos/soft" target="_blank">sfri Library</a>!</div>"
			set currentLength to 0
			set maxLength to 50
			set textColor to "BBBBBB"
			set bgColor to "EEEEEE"
			set linkColor to "027AA2"
			set hoverColor to "FFCC00"
			set barBorderColor to "CCCCCC"
			set barTopColor to "027AA2"
			set barMainColor to "0099CC"
			set barBottomColor to "02B7F2"
			return
		end resetBar
	end script
	script Formularios
		property forminfostuff : "rec = '';
var t = '	';
type1 = '.button.file.hidden.reset.submit.';
type2 = '.text.textarea.password.';
type3 = '.radio.checkbox.';

with (document){
	for (i = 0; i < document.forms.length; i++){
		rec += '{';
		rec += '|name|:*···$' + forms[i].name + '*···$,';
		rec += '|action|:*···$' + forms[i].action + '*···$,';
		rec += '|target|:*···$' + forms[i].target + '*···$,';
		rec += '|method|:*···$' + forms[i].method + '*···$,';
		rec += '|enctype|:*···$' + forms[i].enctype + '*···$,';

		// start elements stuff
		elementstuff = '|elements|:{';
		with (forms[i]){
			numElements = elements.length;
			for (x=0;x<numElements;x++){
				elementstuff += '{';
				elementstuff += '|name|:*···$' + elements[x].name + '*···$,';
				etype = elements[x].type;
				elementstuff += '|type|:*···$' + etype + '*···$,';
				if (type1.indexOf('.'+etype+'.') != -1) { // sólo añadir value
					elementstuff += '|value|:*···$' + elements[x].value + '*···$,';
				} else if (type2.indexOf('.'+etype+'.') != -1) { // más defaultValue
					elementstuff += '|value|:*···$' + elements[x].value + '*···$,';
					elementstuff += '|defaultValue|:*···$' + elements[x].defaultValue + '*···$,';
				} else if (type3.indexOf('.'+etype+'.') != -1) { // radio/checkbox
					elementstuff += '|value|:*···$' + elements[x].value + '*···$,';
					elementstuff += '|checked|:' + elements[x].checked + ',';
					elementstuff += '|defaultValue|:*···$' + elements[x].defaultValue + '*···$,';
				} else { // es un select
					elementstuff += '|selectedIndex|:' + elements[x].selectedIndex + ',';
					// comienza la cosa de las opciones
					optionstuff = '|options|:{';
					numOptions = elements[x].options.length;
					for (y=0;y<numOptions;y++){
						optionstuff += '{';
						optionstuff += '|text|:*···$' + elements[x].options[y].text + '*···$,';
						optionstuff += '|value|:*···$' + elements[x].options[y].value + '*···$,';
						optionstuff += '|selected|:' + elements[x].options[y].selected + ',';
						optionstuff += '|defaultSelected|:' + elements[x].options[y].defaultSelected;
						optionstuff += '},';
					}
					// if there are not options, don't substring stuff
					if (numOptions !=0){
						elementstuff += optionstuff.substring(0,optionstuff.length-1) + '},';
					} else {
						elementstuff += optionstuff + '},';
					}
				}
				// elementstuff += '},';
				elementstuff = elementstuff.substring(0,elementstuff.length-1) + '},';
			}
		}
		// if there are not elements, don't substring stuff
		if (numElements != 0) {
			rec += elementstuff.substring(0,elementstuff.length-1);
		} else {
			rec += elementstuff;
		}
		// end elements stuff

		rec += '}},';
	}
}


// format record for AS
rec = '{' + rec.substring(0,rec.length-1) + '}';"
		global FormID
		global FormElement
		global ElementValue
		on setvalue()
			if class of FormElement = list then
				if class of FormID = string then set FormID to """ & FormID & """
				repeat with i from 1 to count items of FormElement
					set ei to item i of FormElement
					if class of ei = string then set ei to """ & ei & """
					set ev to item i of ElementValue
					if class of ev = string then set ev to """ & ev & """
					set valor to my wathvalue(FormID, ei)
					do JavaScript "document.forms[" & FormID & "].elements[" & ei & "]." & valor & ev in document 1
				end repeat
			else
				if class of FormID = string then set FormID to """ & FormID & """
				if class of FormElement = string then set FormElement to """ & FormElement & """
				if class of ElementValue = string then set ElementValue to """ & ElementValue & """
				set valor to my wathvalue(FormID, FormElement)
				do JavaScript "document.forms[" & FormID & "].elements[" & FormElement & "]." & valor & ElementValue in document 1
			end if
		end setvalue
		to focus()
			if class of FormID = string then set FormID to """ & FormID & """
			if class of FormElement = string then set FormElement to """ & FormElement & """
			try
				do JavaScript "document.forms[" & FormID & "].elements[" & FormElement & "].focus()" in document 1
			on error
				return 0
			end try
		end focus
		to blur()
			if class of FormID = string then set FormID to """ & FormID & """
			if class of FormElement = string then set FormElement to """ & FormElement & """
			try
				do JavaScript "document.forms[" & FormID & "].elements[" & FormElement & "].blur()" in document 1
			on error
				return 0
			end try
		end blur
		on select
			if class of FormID = string then set FormID to """ & FormID & """
			if class of FormElement = string then set FormElement to """ & FormElement & """
			try
				do JavaScript "document.forms[" & FormID & "].elements[" & FormElement & "].select()" in document 1
			on error
				return 0
			end try
		end select
		on submit()
			if class of FormID = string then set FormID to """ & FormID & """
			do JavaScript "document.forms[" & FormID & "].submit()" in document 1
		end submit
		on reset()
			if class of FormID = string then set FormID to """ & FormID & """
			do JavaScript "document.forms[" & FormID & "].reset()" in document 1
		end reset
		on listforms()
			try
				tell application "Safari" to set theResult to (do JavaScript forminfostuff in document 1)
				--> escape quotes in text
				set AppleScript's text item delimiters to """
				set theResult to theResult's text items
				set AppleScript's text item delimiters to "\""
				set theResult to theResult as text
				--> reposite quotes
				set AppleScript's text item delimiters to "*···$"
				set theResult to theResult's text items
				set AppleScript's text item delimiters to """
				set theResult to theResult as text
				set AppleScript's text item delimiters to {""}
				
				return (run script theResult)
			on error
				return 0
			end try
		end listforms
		-- Subroutines
		on wathvalue(fID, eID)
			set valor to do JavaScript "document.forms[" & fID & "].elements[" & eID & "].type" in document 1
			if valor is "radio" or valor is "checkbox" then
				return "checked="
			else if valor starts with "select" then
				return "selectedIndex="
			else
				return "value="
			end if
		end wathvalue
		on StringToList(k, tid)
			set AppleScript's text item delimiters to tid
			set k to every text item of k
			set AppleScript's text item delimiters to ""
			k
		end StringToList
	end script
	to statistics with allinfo
		try
			set allinfo to allinfo
			set thesource to source of document 1 -- GetSource
			set thelength to (count thesource)
			
			set a to "false"
			if allinfo then set a to "true"
			do JavaScript "allInfo = " & a & ";
cL = " & thelength & ";// insert here code length

u = window.location.href;
b = window.location.protocol + '//' + window.location.hostname;
with (document){
	t = title;
	l = lastModified;
	c = 'unknown';
	for(i=0;i<getElementsByTagName('meta').length;i++){
		if (getElementsByTagName('meta').item(i).getAttribute('http-equiv') != null){
			c = getElementsByTagName('meta').item(i).getAttribute('content');
		}
	}
	r = referrer;
	cW = clientWidth;
	cH = clientHeight;
}

start = '{PageTitle:"' + t + '",PageURL:"' + u + '",BaseURL:"' + b + '",LastModified:"' + l + '",Charset:"' + c + '",Referrer:"' + r + '",CodeLength:' + cL + ',clientWidth:' + cW + ',clientHeight:' + cH;

if (allInfo){
	start  += ',Forms:{';
	
	formLength = document.forms.length;
	sep = ',';
	for(i=0;i<formLength;i++){
		if (i == formLength-1) sep = '';
		f = document.forms[i];
		start += '{formname:"' +f.name + '",formaction:"'+f.action+'",formmethod:"' + f.method+'"}' + sep;
	}
	
	start += '},ImageURLs:{';
	imgLength = document.images.length;
	sep = ',';
	for (i=0;i<imgLength;i++){
		if (i == imgLength-1) sep = '';
		start += '"' + document.images[i].src + '"' + sep;
	}
	start += '},Objects:{';
	objLength = document.getElementsByTagName('embed').length;
	sep = ',';
	for (i=0;i<objLength;i++){
		if (i == objLength-1) sep = '';
		start += '"' + document.getElementsByTagName('embed').item(i).src + '"' + sep;
	}
	start += '},Links:{';
	linkLength = document.links.length;
	sep = ',';
	for (i=0;i<linkLength;i++){
		if (i == linkLength-1) sep = '';
		start += '"' + document.links[i].href + '"' + sep;
	}
	start += '}}';
} else {
	start += '}';
}
start" in document 1
			run script result
		on error
			return 0
		end try
	end statistics
	on displayconfirm(msg)
		do JavaScript "confirm("" & msg & "")" in document 1
		run script result
	end displayconfirm
	on displayprompt(msg, ans)
		do JavaScript "x=prompt("" & msg & "", "" & ans & "");if(!x)false" in document 1
		if result = "false" then
			run script "false"
		else
			result
		end if
	end displayprompt
	on loadpage(wheretogo)
		try
			do JavaScript "window.history.go(" & wheretogo & ")" in document 1
		on error
			return 0
		end try
	end loadpage
	on location(frame, theloc)
		try
			if frame ? "" then
				if class of frame = string then
					set testCode to "frames["" & frame & ""].location.href"
					set realCode to "frames["" & frame & ""].location.href="" & theloc & """
				else
					set testCode to "frames[" & frame & "].location.href"
					set realCode to "frames[" & frame & "].location.href="" & theloc & """
				end if
				if (do JavaScript testCode in document 1) = "" then return 0
				set theResult to (do JavaScript realCode in document 1)
			else
				do JavaScript "window.location="" & theloc & """ in document 1
			end if
		on error
			return 0
		end try
	end location
	to fullscreen()
		do JavaScript "self.moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight)" in document 1
	end fullscreen
	to resizewin to {w, H, centered}
		try
			set theCode to "resizeTo(("" & w & ""),("" & H & ""))"
			if centered then
				if (w = 0) and (H = 0) then
					set x to 0
					set y to 0
					set theCode to (do JavaScript ""resizeTo((\"" + screen.availWidth + "\"),(\"" + screen.availHeight + "\"))"" in document 1)
				else
					set {x, y} to every paragraph of (do JavaScript "Math.round((screen.availWidth)/2 - (" & w & "/2)) + "\r" + Math.round((screen.availHeight)/2 - (" & H & "/2))" in document 1)
					set {x, y} to {x as integer, y as integer}
				end if
				if x < 0 or y < 0 then return 0
				set theCode to theCode & return & "moveTo(" & x & "," & y & ")"
			end if
			repeat 2 times
				do JavaScript theCode in document 1
			end repeat
		on error
			return 0
		end try
	end resizewin
	to movewin to {x, y}
		try
			do JavaScript "window.moveTo(" & x & "," & y & ")" in document 1
		on error
			return 0
		end try
	end movewin
	to scrollwin to {x, y}
		try
			do JavaScript "window.scroll(" & x & "," & y & ")" in document 1
		on error
			return 0
		end try
	end scrollwin
	to focuswin(docObject)
		do JavaScript "self.focus()" in docObject
	end focuswin
	on aboutmonitor()
		try
			set {availablew, availableh, realw, realh, Colores} to every paragraph of (do JavaScript "screen.availWidth + "\r" + screen.availHeight +  "\r" + screen.width + "\r" + screen.height + "\r" + Math.pow(2,screen.colorDepth)" in document 1)
			set k2 to {Resolution:{realw as number, realh as number}} & {AvailableSize:{availablew as number, availableh as number}} & {Colores:Colores as real}
		on error
			return 0
		end try
	end aboutmonitor
	on aboutnavigator()
		set {appCodeName, appname, appversion, useragent, language, platform, product, productSub, vendor, javaEnabled} to paragraphs of (do JavaScript "CR = '\r';with(navigator){appCodeName + CR + appName + CR + appVersion + CR + userAgent + CR + language + CR + platform + CR + product + CR + productSub + CR + vendor + CR + javaEnabled()}" in document 1)
		return {appCodeName:appCodeName} & {appname:appname} & {appversion:appversion} & {useragent:useragent} & {language:language} & {platform:platform} & {product:product} & {productSub:productSub} & {vendor:vendor} & {javaEnabled:run script javaEnabled}
	end aboutnavigator
	on aboutplugins()
		set k to items 1 thru -2 of (every paragraph of (do JavaScript "n= new Array();for (var i=0; i<navigator.plugins.length;i++) {x = navigator.plugins[i];n = n + x.name + "•" + x.filename + "•" + x.description + "•" + x[0].type + "•" + x[0].suffixes + "\r"}" in document 1))
		set pluginfo to {}
		repeat with i in k
			set {plname, pfname, desc, mtype, PSuffixes} to (my StringToList(i))
			set pluginfo to pluginfo & {{PName:plname} & {PFilename:pfname} & {PDescription:desc} & {PMimeType:mtype} & {PSuffixes:PSuffixes}}
		end repeat
		pluginfo
	end aboutplugins
	on aboutmimetype(num)
		if num = "all" then
			set k to items 1 thru -2 of (every paragraph of (do JavaScript "n="";for (var i=0; i<navigator.mimeTypes.length;i++) {x = navigator.mimeTypes[i];n = n + x.suffixes + "•" + x.type  + "•" +  x.description + "\r"};" in document 1))
			set mimeTypes to {}
			repeat with i in k
				set {MTSuffixes, MTType, MTDescription} to (my StringToList(i))
				set mimeTypes to mimeTypes & {{MTSuffixes:MTSuffixes} & {MTType:MTType} & {MTDescription:MTDescription}}
			end repeat
		else
			if class of num = list then
				set AppleScript's text item delimiters to ","
				set num to num as text
				set AppleScript's text item delimiters to {""}
			else
				set num to """ & num & """
			end if
			try
				set k to items 1 thru -2 of (every paragraph of (do JavaScript "a = new Array(" & num & ");n="";for (var i=0; i<a.length;i++) {w = a[i];x = navigator.mimeTypes[w];if (x.enabledPlugin != null) {z=true+"•" + x.enabledPlugin.name} else {z=false+"•" + ""}n = n + x.suffixes + "•" + x.type  + "•" +  x.description + "•" +  z + "\r";};n" in document 1))
			on error
				return 0
			end try
			set mimeTypes to {}
			repeat with i in k
				set {MTSuffixes, MTType, MTDescription, PluginEnabled, PluginName} to (my StringToList(i))
				set rec to {MTSuffixes:MTSuffixes} & {MTType:MTType} & {MTDescription:MTDescription} & {PluginEnabled:run script PluginEnabled} & {PluginName:PluginName}
				set mimeTypes to mimeTypes & {rec}
			end repeat
		end if
		return mimeTypes
	end aboutmimetype
	on aboutimage(imgID)
		if imgID = "all" then
			try
				set k to items 1 thru -2 of (every paragraph of (do JavaScript "n="";for (var i=0; i<document.images.length;i++) {with (document.images[i]) {a=name,b=src,c=width,d=height,e=complete,f=border,g=lowsrc,h=vspace,j=hspace};n = n + a + "•" +b+"•" +c+"•" +d+"•" +e+"•" +f+"•" +g+"•" +h+"•" +j + "\r"};n" in document 1))
			on error
				return 0
			end try
			set allImgs to {}
			repeat with i in k
				set {n, src, w, H, loaded, border, lowsrc, vspace, hspace} to (my StringToList(i))
				set allImgs to allImgs & {{name:n} & {src:src} & {width:w as integer} & {height:H as integer} & {complete:loaded} & {border:border as integer} & {lowsrc:lowsrc} & {vspace:vspace as integer} & {hspace:hspace as integer}}
			end repeat
		else
			if class of imgID = list then
				set AppleScript's text item delimiters to ","
				set imgID to imgID as text
				set AppleScript's text item delimiters to ""
			else
				set imgID to """ & imgID & """
			end if
			try
				set k to items 1 thru -2 of (every paragraph of (do JavaScript "a = new Array(" & imgID & ");n="";for (var i=0; i<a.length;i++) {w = a[i];with (document.images[w]) {aa=name,b=src,c=width,d=height,e=complete,f=border,g=lowsrc,h=vspace,j=hspace};n = n + aa + "•" +b+"•" +c+"•" +d+"•" +e+"•" +f+"•" +g+"•" +h+"•" +j + "\r"};n" in document 1))
			on error
				return 0
			end try
			set allImgs to {}
			repeat with i in k
				set {n, src, w, H, loaded, border, lowsrc, vspace, hspace} to (my StringToList(i))
				set allImgs to allImgs & {{name:n} & {src:src} & {width:w as integer} & {height:H as integer} & {complete:loaded} & {border:border as integer} & {lowsrc:lowsrc} & {vspace:vspace as integer} & {hspace:hspace as integer}}
			end repeat
		end if
		return allImgs
	end aboutimage
	on aboutme()
		return AboutInfo
	end aboutme
	to extractBookmarks()
		try
			set x to paragraphs of (do shell script "defaults read ~/Library/Safari/Bookmarks | grep -w URLString | sed s/'URLString \= "'//g | sed s/'"; $'//g | sed s/^[[:space:]]*//g")
			set y to paragraphs of (do shell script "defaults read ~/Library/Safari/Bookmarks | grep -w title | sed s/'title \= "'//g |   sed s/'title \= '//g | sed s/'"; $'//g | sed s/'; $'//g | sed s/^[[:space:]]*//g")
			set Z to {}
			repeat with i from 1 to count x
				set Z's end to {|name|:y's item i, |URL|:x's item i}
			end repeat
			return Z
		on error
			return 0
		end try
	end extractBookmarks
	to extractImages()
		try
			rest of paragraphs of (do JavaScript "function sfriTmf(sfriObj){
	if (sfriObj.frames.length == 0) { // extract images from this page
		for (sfriQ=0;sfriQ<sfriObj.document.images.length;sfriQ++){
			sfriTprocessImg(sfriObj.document.images[sfriQ].src);
		}
	} else { // rotate again
		for (sfriQ=0;sfriQ<sfriObj.frames.length;sfriQ++){
			sfriTmf(sfriObj.frames[sfriQ]);
		}
	}
}
function sfriTprocessImg(sfriTimg){
	sfriTPB = '\r' + sfriTimg + '%%%';
	if (sfriTz.indexOf(sfriTPB) == -1) {
		sfriTimgFake = sfriTimg.toLowerCase();
		sfriTimgLength = sfriTimg.length;
		if ((sfriTimgLength == sfriTimgFake.lastIndexOf('.jpg') + 4) || (sfriTimgLength == sfriTimgFake.lastIndexOf('.gif') + 4) || (sfriTimgLength == sfriTimgFake.lastIndexOf('.jpeg') + 5) || (sfriTimgLength == sfriTimgFake.lastIndexOf('.png') + 4)) {
			sfriTz += sfriTPB;
		}
	}
}

sfriTw = top.frames.length;
sfriTz = '';
if (sfriTw == 0) {
	sfriTx = top.document.images.length;
	for (sfriTi = 0; sfriTi < sfriTx; sfriTi++){
		sfriTprocessImg(top.document.images[sfriTi].src);
	}
} else {
	fframes = true;
	for (sfriTi = 0; sfriTi < sfriTw; sfriTi++){ // repeat with every frame
		if (top.frames[sfriTi].location.href) {
			sfriTmf(top.frames[sfriTi]);
			fframes = false;
		}
	}
	if (fframes) {
		for (sfriQ=0;sfriQ<document.images.length;sfriQ++){
			sfriTprocessImg(document.images[sfriQ].src);
		}
	}
}

sfriTz = sfriTz.split('%%%');
sfriTz = sfriTz.join('');
sfriTz" in document 1)
		on error msg
			display dialog msg
			{}
		end try
	end extractImages
	to extractLinks()
		try
			rest of paragraphs of (do JavaScript "
function mf(obj){
	if (obj.frames.length == 0) { // extract links from this page
		for (q=0;q<obj.document.links.length;q++){
			processLink(obj.document.links[q].href);
		}
	} else { // rotate again
		for (q=0;q<obj.frames.length;q++){
			mf(obj.frames[q]);
		}
	}
}
//var okURLs = '%%http://%%https://%%ftp://%%mailto://%%file://%%news://%%hotline:%%ed2k://%%carracho://%%';
function processLink(l){
	if (z.indexOf('\r'+l+'%%%') == -1 && l != '' && l.indexOf('javascript') != 0 && l.indexOf('#') != 0) {
		if (l.indexOf('http://') == 0 || l.indexOf('https://') == 0 || l.indexOf('ftp://') == 0  || l.indexOf('mailto://') == 0  || l.indexOf('file://') == 0  || l.indexOf('news://') == 0 ) { // añadir, sin más
			z += '\r' + l + '%%%';
		} else {
			if (l.indexOf('/') == 0) { // eg, '/index.html'
				docHost = getHost(top.window);
				petabyte = '\r' + docHost + l + '%%%';
				if (z.indexOf(petabyte) == -1) { z += petabyte }
			} else { // eg, 'index.html' or '../index.html'
				docURL = getURL(top.window);
				ns = l.split('../');
				if (ns.length == 1) { // eg, 'index.html' or 'kaka/pepe.html'
					petabyte = '\r' + docURL + '/' + ns + '%%%';
					if (z.indexOf(petabyte) == -1) { z += petabyte }
				} else { // eg, '../index.html' or '../kaka/index.html';
					lessURL = docURL.split('/');
					lessURL = lessURL.slice(0,lessURL.length - ns.length + 1);
					lessURL = lessURL.join('/');
					petabyte = '\r' + lessURL + '/' +  ns[ns.length - 1] + '%%%';
					if (z.indexOf(petabyte) == -1) { z += petabyte }
				}
			}
		}
	}
}
function getHost(w){
	return w.location.protocol + '//' + w.location.hostname;
}
function getURL(w){
	louro = w.location.href;
	zwx = louro.lastIndexOf('/');
	louro = louro.substring(0,zwx);
	return louro
}

w = top.frames.length;
z = '';
if (w == 0) {
	x = top.document.links.length;
	for (i = 0; i < x; i++){
		processLink(top.document.links[i].href);
	}
} else {
	fframes = true;
	for (i = 0; i < w; i++){ // repeat with every frame
		if (top.frames[i].location.href) {
			mf(top.frames[i]);
			fframes = false;
		}
	}
	if (fframes) {
		for (sfriQ=0;sfriQ<document.links.length;sfriQ++){
			processLink(document.links[sfriQ].href);
		}
	}
}
z = z.split('%%%');
z = z.join('');
z" in document 1)
		on error
			{}
		end try
	end extractLinks
	-->> other handlers
	on ExtractObjects(obj, v)
		set y to (do JavaScript "n= new Array();for (var i=0; i<document." & obj & ".length;i++) {n = n + (document." & obj & "[i]." & v & ") + "\r"}" in document 1)
		try
			set allLinks to items 1 thru -2 of (paragraphs of y)
		on error
			return {}
		end try
	end ExtractObjects
	on ExtractObjects2(obj, v)
		set y to (do JavaScript "n= new Array();for (var i=0; i<document.getElementsByTagName('" & obj & "').length;i++) {n = n + (document.getElementsByTagName('" & obj & "').item(i)." & v & ") + "\r"}" in document 1)
		try
			set allLinks to items 1 thru -2 of (paragraphs of y)
		on error
			return {}
		end try
	end ExtractObjects2
	on returnprashes(tid, off, txt)
		set listreturned to {}
		set AppleScript's text item delimiters to tid
		set txt to txt's every text item
		repeat with i from 1 to count txt
			set itemI to item i of txt
			if off is in contents of itemI then
				try
					set founded to (offset of off in itemI)
					set founded to (text from character founded to last character of itemI)
					set listreturned to listreturned & founded
				end try
			end if
		end repeat
		set AppleScript's text item delimiters to {""}
		return listreturned
	end returnprashes
	on SearchReplace(s, r, theText)
		tell (a reference to AppleScript's text item delimiters)
			set {oldTID, contents} to {contents, {s}}
			try
				set {lT, contents} to {(text items of theText), {r}}
				set {nT, contents} to {(lT as text), oldTID}
				return nT
			on error msg number n
				set contents to oldTID
				error msg number n
			end try
		end tell
	end SearchReplace
	on AbsolURL(bu, u)
		if ":" is in contents of u then
			return u
		else
			try
				if first item of u ? "/" then
					set AppleScript's text item delimiters to "../"
					set k to every text item of u
					set w to (count k)
					if w = 1 then
						set del to "/"
					else
						set {del, k} to {"", {k's item -2, k's item -1}}
					end if
				else
					set {k, w, del} to {u, -3, ""}
				end if
				set AppleScript's text item delimiters to "/"
				set k2 to ((text items from text item 1 of bu to (-1 - w) of bu) as text) & del & (k as text)
				set AppleScript's text item delimiters to ""
				return k2
			on error
				return u
			end try
		end if
	end AbsolURL
	on StringToList(k)
		set AppleScript's text item delimiters to "•"
		set k to every text item of k
		set AppleScript's text item delimiters to ""
		k
	end StringToList
	
	-- éste es gratis...
	on offsetOf(theItem, theList)
		set i to 0
		repeat with ListItem in the theList
			set i to i + 1
			if (theItem = contents of ListItem) then exit repeat
		end repeat
		i
	end offsetOf
end using terms from

Your code works pretty fine here :wink:
Are you waiting to the page being fully loaded before letting the code go ahead? (This is here when you see “http://www.dishusa.com/index.html?kbid=1002” in the address bar and the page is fully loaded)
Safari 1.2.4

I have the latest version of safari, 1.2 which I downloaded from apple’s site. You showed 1.2.4? Is that correct?

On any web site I go to that sets cookies I get the same result and the cookies are not deleted.

Why would it not work for you and not for me. I posted the error log I was getting here:

http://bbs.applescript.net/viewtopic.php?t=10646

PLUS, I tested it on another machine with the same results. It will not delete cookies. I also now found safari 1.2.4 and installed it. I get the same results. It will not delete any cookies from any website I set in the URL paramater.

I’ve found some times cookies which I can’t delete, but I’ve tested the site you said and it works flawlessly in the two different browsers I tried.
Also, what puzzles me is the existence of two cookies with the same name, as you describe in your error log (another post): “kbid=1001; kbid=1001”. I can’t concibe how you can have two cookies with the same name. It should be impossible, unless they are sent from different domains… (eg, “www.foo.com” and “.foo.com”) or different paths (eg, “/” and “/foo”), but this shouldn’t be the case.
Also puzzles me the sentence “It will not delete any cookies from any website”.
Sorry, but I have no more ideas :frowning:

JJ, You are correct with the domain. One cookie is written as www.dishusa and the other as .dishusa.

What are the paramaters of the system you are using? Maybe I can narrow something down.

Teorically, the “default” domain, since the cookie is set by javascript itself. So, if the sent cookie is “www.foo.com”, it should override the same cookie of the same name of the same domain…