Help with an error in a Safari script

I’m trying to write script that would get the current Safari tab and open it in a new window.

I also want it to move the bounds of the new window to the right slightly (compared to the previous window), and close that tab/URL in the ‘old window’.

tell application "Safari" to set theBounds to the bounds of window 1


tell theBounds to set {leftEdge, topEdge, rightEdge, bottomEdge} to {item 1, item 2, item 3, item 4}
set newWindowBounds to "({" & (leftEdge + 100) & ", " & topEdge & ", " & (rightEdge + 100) & ", " & bottomEdge & "} as rectange)"


tell application "Safari"
	set theURL to URL of current tab of front window
	
	set newWindow to make new document at end of documents
	set URL of newWindow to theURL
	set the bounds of window 1 to newWindowBounds
	-- -> error number -1700 from "({551, 25, 1652, 993} as rectange)" to rectangle
	
	close current tab of window 2
	
end tell

The script runs OK until it gets to setting the bounds of the new window, it then throws an error:

I’m hoping the problem is something simple. Does anyone know why I get the error? :slight_smile:

Hi. Rectangle is misspelt, and Safari—at least under Mojave—has no such property. There also appears to be a confusion with geometric bounds; Safari uses another arrangement.


tell application "Safari"
	set {leftmost, topmost, pixelWidth, pixelHeight} to window 1's bounds
	make document with properties {URL:(get window 1's documents's URL)}
	tell window 1 to set bounds to {leftmost + 100, topmost + 100, pixelWidth, pixelHeight}
end tell

That’s great, thanks a lot Marc!