Detect Safari if statement

Hi,

I am currently working on a newsletter bulk sending script and I am trying to stop safari from opening a new tab every time it loops round to a new email so far I have:


			tell application "Safari"
				activate
				if current tab = {URL:"***.com"} then
					tell application "System Events"
						keystroke "a" using command down
						delay 2
						keystroke "c" using command down
						tell application "Mail"
							activate
							delay 1
							tell application "System Events"
								keystroke tab
								delay 1
								keystroke tab
								delay 1
								keystroke "test"
								delay 1
								keystroke tab
								keystroke "v" using command down
								
								tell application "System Events"
									tell process "Mail"
										repeat with i from 1 to count of EmailAddresses
											keystroke "d" using {command down, shift down}
										end repeat
									end tell
								end tell
							end tell
						end tell
					end tell
					
					
				else
					activate
					tell window 1 to set current tab to make new tab with properties {URL:"***.com"}
					delay 2
					tell application "System Events"
						keystroke "a" using command down
						delay 2
						keystroke "c" using command down
						tell application "Mail"
							activate
							delay 1
							tell application "System Events"
								keystroke tab
								delay 1
								keystroke tab
								delay 1
								keystroke "test"
								delay 1
								keystroke tab
								keystroke "v" using command down
								
								tell application "System Events"
									tell process "Mail"
										repeat with i from 1 to count of EmailAddresses
											keystroke "d" using {command down, shift down}
										end repeat
									end tell
								end tell
							end tell
						end tell
					end tell
				end if
			end tell
		end tell
	end repeat
	
end tell

But I get an error when running it not compiling “AppleScript Error: Safari got an error: Can’t get current tab.”

Is there a permission I need to change or something?

Any help would be great!

Thanks,
Bruce

P.S. I did start this at the end of a forum post but I though I’d better move it to a new post as it was not apart of the question being asked.

found the problem I told safari to look in window 1 for the tab but it is still opening a new tab.

Here is the code at the moment:


set EmailAddresses to theEmailGroup
tell application "Mail"
	activate
	repeat with i from 1 to count of EmailAddresses
		tell (make new outgoing message)
			set visible to true
			make new to recipient at end of to recipients with properties {address:item i of EmailAddresses}
			delay 2
			tell application "Safari"
				activate
				if current tab of window 1 = {URL:"***.com"} then
					tell application "System Events"
						keystroke "a" using command down
						delay 2
						keystroke "c" using command down
						tell application "Mail"
							activate
							delay 1
							tell application "System Events"
								keystroke tab
								delay 1
								keystroke tab
								delay 1
								keystroke "test"
								delay 1
								keystroke tab
								keystroke "v" using command down
								
								tell application "System Events"
									tell process "Mail"
										repeat with i from 1 to count of EmailAddresses
											keystroke "d" using {command down, shift down}
										end repeat
									end tell
								end tell
							end tell
						end tell
					end tell
					
					
				else
					activate
					tell window 1 to set current tab to make new tab with properties {URL:"**.com"}
					delay 2
					tell application "System Events"
						keystroke "a" using command down
						delay 2
						keystroke "c" using command down
						tell application "Mail"
							activate
							delay 1
							tell application "System Events"
								keystroke tab
								delay 1
								keystroke tab
								delay 1
								keystroke "test"
								delay 1
								keystroke tab
								keystroke "v" using command down
								
								tell application "System Events"
									tell process "Mail"
										repeat with i from 1 to count of EmailAddresses
											keystroke "d" using {command down, shift down}
										end repeat
									end tell
								end tell
							end tell
						end tell
					end tell
				end if
			end tell
		end tell
	end repeat
	
end tell

fixed it myself

admin can close if they want. I might share the script when ran through testing and use for a while !

Bruce

P.S. sorry for bumps