Pls I want understand apple script

hello I asked help for this http://bbs.applescript.net/viewtopic.php?pid=58434#p58434

using terms from application "Address Book"
	on action property
		return "phone"
	end action property
	
	on action title for p with e
		return "Dial with eyeBeam"
	end action title
	
	on should enable action for p with e
		return true
	end should enable action
	
	on perform action for p with e
		set newPhone to characters of (value of e as string)
		repeat with i in newPhone
			if contents of i = "+" then set contents of i to "00"
		end repeat
		repeat with i in newPhone
			if contents of i = " " then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = "-" then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = "(" then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = ")" then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = "." then set contents of i to ""
		end repeat
		tell application "X-Lite"
			activate
			dial (newPhone as string)
		end tell
		return true
	end perform action
end using terms from

so I thought to do this :

using terms from application "Address Book"
	on action property
		return "phone"
	end action property
	
	on action title for p with e
		return "Cerca con Pagine Bianche"
	end action title
	
	on should enable action for p with e
		return true
	end should enable action
	
	on perform action for p with e
		set newPhone to characters of (value of e as string)
		repeat with i in newPhone
			if contents of i = "+" then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = " " then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = "-" then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = "(" then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = ")" then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = "." then set contents of i to ""
		end repeat
		repeat with i in newPhone
			if contents of i = "" then set contents of i to "http://www.paginebianche.it/execute.cgi?btt=1&tl=2&tr=106&cb=&qs="
		end repeat
		tell application "Safari"
			activate
			open location (newPhone as string)
		end tell
		return true
	end perform action
end using terms from

That should add phone nunber to “http://www.paginebianche.it/execute.cgi?btt=1&tl=2&tr=106&cb=&qs=” + (newPhone as string) - +39 …

but it’s all wrong :frowning:

I thought that if contents of i = “” then the contest should be “http://www.paginebianche.it/execute.cgi?btt=1&tl=2&tr=106&cb=&qs=” so newPhone should be now "http://www.paginebianche.it/execute.cgi?btt=1&tl=2&tr=106&cb=&qs=(newPhone as string)

but the final resul change all the time depending on numbers .

if number is : +39 066789376 it’s ok
if number is : +39066789376 it’s bad

But the script say : if contents of i = " " then set contents of i to “”

so why in number “+39 066789376” +39 get removed
and in number “+39066789376” only plus get removed ?

I can’t understand it .

Pls Help

Thanks

What you are trying to do in the perform action for p with e is to filter out illegal characters. The problem is that you are not changing the characters in the newPhone vairable but rather the variable that you are using to step through the characters. I don’t see anywhere that you are updating the information to newPhone. I’m not sure if there is a problem with changing the value of “repeating” variable within the repeat line. What you really need to do is to create a new variable to hold your filtered variable as you go along, I know that my example below does not work if I use the repeat with a in x.
Try this:

set OldPhone to "+39 06-67 8()9.376"
set newPhone to ""
repeat with i from 1 to count of OldPhone
	set aNum to character i of OldPhone
	if aNum is "+" or aNum is " " or aNum is "-" or aNum is "(" or aNum is ")" or aNum is "." then set aNum to ""
	set newPhone to newPhone & aNum
end repeat

You could also use a list for your newPhone and coerce it to a string later:

set OldPhone to "+39 06-67 8()9.376"
set newPhone to {}
repeat with i from 1 to count of OldPhone
	set aNum to character i of OldPhone
	if aNum is "+" or aNum is " " or aNum is "-" or aNum is "(" or aNum is ")" or aNum is "." then set aNum to ""
	copy aNum to end of newPhone
end repeat
return newPhone as string

I may be wrong in my assessment, and if I am someone will probably correct me, but the above examples should work. I tried your script, and I must admit my ignorance in scripting address book I’m usually working with Adobe apps, but I couldnt get it to do anything. I don’t see any run portion, just a bunch of handlers.