How do I create two new Safari windows in different positions? - applescript

I'm trying to write a script which opens two Safari windows with different bounds, at different positions on the desktop, like so:
The {pixels wide, pixels high} labels are more accurate than the actual proportions of the boxes. The problem I'm having is that I can set the bounds of the window on the left exactly how I want - as it's the first one the script generates - but when I try to specify the bounds of the second window on the right, its position is tied to the position of the first window, and it's either constrained within the bounds of the first window or - if I tell it to "spawn" outside the bounds of the first window - doesn't appear at all.
# Desktop: {1280, 800}
tell application "Safari"
activate
make new document with properties {URL:"https://www.google.com"}
set bounds of front window to {25, 25, 550, 750}
make new document with properties {URL:"https://www.google.com"}
set bounds of front window to {25, 25, 700, 750}
end tell
As you'll see, the script currently creates both windows at the same {25, 25} co-ordinate for now as this is the closest functional version I have to what I want.
How can I set the bounds of the second, right-hand window to appear as shown in the image regardless of the bounds of the first window on the left?

The value of the bounds property is returned as a four item list of integers representing the bounding area of the window on the screen:
List item 1: {x1, y1, x2, y2}
The distance in pixels from the left side of the screen to the left side of the window.
List item 2: {x1, y1, x2, y2}
The distance in pixels from the top of the screen to the top of the window.
List item 3: {x1, y1, x2, y2}
The distance in pixels from the left side of the screen to the right side of the window.
List item 4: {x1, y1, x2, y2}
The distance in pixels from the top of the screen to the bottom of the window.
The bounds for the first window with a width of 550 and height of 750 with a 25 pixel offset would be:
{25, 25, 575, 775}
The bounds for the second window with a width of 700 and height of 750 and no space between it and the first window would be:
{575, 25, 1275, 775}
This will give you the two windows of the sizes show in your diagram, however the spacing is not exactly as shown.
tell application "Safari"
activate
make new document with properties {URL:"https://www.google.com"}
set bounds of front window to {25, 25, 575, 775}
make new document with properties {URL:"https://www.google.com"}
set bounds of front window to {575, 25, 1275, 775}
end tell

Related

Adding controller buttons to prompt text?

I want to make a controller button prompt in my game where it says 'Press X to Join', but I want the X to be an actual graphic of the 'X' button, like how it is in many games. How would I go about doing that? Right now I'm just putting a big space in my prompt text and putting a UI Image of the button in it, but I want to know if there's a better way about it.
For the sake of scaling to different resolution sizes, you would wanna scale the anchors of the UI elements correctly and have an appropriate parent-child relation tree in Unity's hierarchy.
The red box is the hierarchy.
The 2 green boxes shows ways of scaling the anchors.
The orange box shows the end result of it.
Anchors in combination with their relative position, allows Unity's UI elements to scale up and down according to screen size.
So for example if you say that an anchor is at 0.25x, that would be that its anchored at 25% of for example the x axis. Same goes if you set it for the y axis, just the vertical instead of horizontal anchoring.
You can use the anchors to adjust a minimum and a maximum anchor which the elements may float within, they may have the same value as well, then it's a fixed anchor point.
To clarify, I suggest that you use a panel to hold 2 text elements and the image with the X, each text element being on the left and right side of the X instead of having spacing inside the UI text elements. To keep correct spacing you then must use anchor points. This way your spacing stays correct despite changing screen and resolution sizes.
Please note that the "left", "top", "right" and "bottom" values are then relative to the anchor points. So if you move "left" 5 pixels, those 5 pixels will be out from the relative anchor point.
Here's the values I used:
My left text is at 0.25x, right text is at 0.8x, image is at 0.5x.
The panel holding the 3 is at 0.2 minimum x to 0.8 max x, same goes for y axis.
The largest parent panel is stretched to max fit in the canvas.

Use auto layout to position button near the center

I'm using auto layout in Xcode and I have some buttons I want to be near the center, but not on it. I know I can use alignment constraints to be exactly in the center, in this menu:
However, I want to not be exactly in the center, lets say 50 pixels up and to the right. How can I do this? I'm sure it's an easy thing to do, but I can't seem to find anything elsewhere on the web.
If you want the center of your button to be 50 points up and to the right of the parent view's center you can use a center x alignment constraint and a center y alignment constraint and set the center x alignment constraint's constant to 50 and the center y alignment constraint's constant to -50.
Create a view with size 50 * 50. Then place this view exactly at the center using auto layout.
Next you need to place your button using vertical space and horizontal space in order to be aligned to the upper right corner of the view.
Finally make the view transparent.

With x11 get window at coordinates

I want to get the top most window that is at position x and y. In Winapi I do this with WindowFromPoint seen here: https://msdn.microsoft.com/en-us/library/ms633558%28v=vs.85%29.aspx
Is there any equivalent in x11? I have covered the entire screen with a window and i want to know all the windows that are at the point in z order.
XQueryTree gives list of window in the stacking order. You would need to query dimensions for every window in the list and stop when your point is within rectangle

AppleScript - what are bounds?

I am AppleScripting Adobe Illustrator CS3. Here is (part of) my code:
tell application "Adobe Illustrator"
tell newDocument
make new rectangle with properties {bounds:{200.0, 400.0, 300.0, 200.0}}
end tell
end tell
I copied the make new rectangle part from page 153 of this, from Adobe's website.
But what are the bounds??? When I run the script, they don't match up with the co-ordinates of the rectangle:
How do I convert from co-ordinates to bounds? My canvas size is 1920 by 1080.
Well, as it says in the reference on p.153, the bounds are as follows:
left-most horizontal
top vertical
right-most horizontal
bottom vertical
bound of the rectangle, measured from the bottom left corner (0, 0). The X and Y coordinates you see will be the coordinates of the rectangle's center point. However, the width and height in your screenshot are strange: when running your code (with bounds:{200, 400, 300, 200}), I obtained a rectangle having its center at X=250, Y=300, and dimensions of W=100, H=200, as expected.

Confusing (x, y) origins with sub-views in interface builder

I have a view in interface builder, and then a subview within that view. I place the sub-view visually near the upper left corner within its parent. I would therefore expect the x, y coordinates of the sub-views frame to be something close to (20,20), but instead IB tells me it is something like (230,432). If I then adjust the X, Y coords in the properties window to something like (20,20), the sub-view flies off the screen towards the upper-left... What is the deal? BTW, it is an iPad specific view size, where the top/parent view is sized 768x1004.
In the Size & Position section, in the grid on the left, make sure the top-left corner dot is selected. The dot selected in this grid determines what the X and Y coordinates refer to.
You may have the center dot selected and so the X,Y coordinates indicate the coordinates of the sub-view's center relative to the parent.

Resources