Toggle between different Safari Windows & Tabs

I’m really new at Applescript and it’s not been easy picking this up with the book. On a side note, if anyone has a tip on the best ways to learn this, please let me know. Used C++ once in college but that was awhile ago.

My script opens a couple safari windows, each with multiple tabs. What’s the script that will allow me to toggle between safari windows and also through the tabs of each window?


tell application "Safari"
	tell window 1
		set current tab to tab 2 -- or whatever tab number you want to go to ( tab -1 ) is last tab
	end tell
end tell

GUI scripting is not needed at all
next tab:


tell application "Safari"
	tell window 1
		set i to index of current tab
		set i to i + 1
		if i > (count tabs) then set i to 1
		set current tab to tab i
	end tell
end tell

next window:


tell application "Safari"
	tell (windows whose visible is true)
		set index of last window to 1
	end tell
end tell

THANKS!!! That worked perfectly.