--------------------------------------------------------------------------------
--
--  ADOBE SYSTEMS INCORPORATED
--  Copyright 2006 Adobe Systems Incorporated
--  All Rights Reserved.
--
--  NOTICE: Adobe permits you to use, modify, and distribute this file
--  in accordance with the terms of the license agreement accompanying it.
--
--------------------------------------------------------------------------------

-- tell Safari to close all windows that have the specified URL
tell application "Safari"
	-- 'closed' keeps track of whether we have closed any documents
	set closed to false

	set done to false
	repeat until done
		set done to true
		repeat with w in windows
			try
				repeat with t in tabs of w
					if URL of t is item 1 of argv then
						close t
						set closed to true

						-- since we have closed a document, we must restart the loop
						set done to false
						exit repeat
					end if
				end repeat
			end try
		end repeat
	end repeat

	-- if we closed at least one Safari window, and no more are
	-- open, then tell Safari to exit
	if closed and (count of documents) is 0 then		
		quit
		set closed to "appquit"
	end if

	-- return true if we closed at least one window, false if not
	closed
end tell
