I'm a brand new AppleScript initiate. I was at a Developer Summit and needed to stop messing with my windows so much. So I looked up scripting the window sizing and positioning. I was on my MacBook Pro and so I wrote the following code and placed in Automator as a Service whic I then saved to HardDrive>Users>User>Library>Services.
tell application "System Events"
set myTargetApplication to name of the first process whose frontmost is true
end tell
tell application myTargetApplication
-- This line is what we use when we need to grab that bounds of a window.
-- set currentBounds to bounds of the first window
set bounds of the first window to {61, 46, 1261, 777}
end tell
I would write the script in "Script Editor" and test it with the commented out line uncommented and the line after it commented. Then I could position the window like I want and get the settings I needed to apply. I got the settings, and pasted them in the line right before "end tell" and they worked.
I set this as a service and now I can make ANY window (from Service) size to what I needed.
I arrived home and connected to my dual monitor, a 32" Acer, and everytime I would run the script in my big monitor it would JUMP to the MacBook Window.
So I tweaked this and that, tried several things, looked things up, and during a run did this:
tell application "System Events"
set myTargetApplication to name of the first process whose frontmost is true
end tell
tell application myTargetApplication
-- This line is what we use when we need to grab that bounds of a window.
-- set currentBounds to bounds of the first window
set bounds of the first window to {1299, 38, 3182, 1062}
end tell
I did the same thing in Automator... saved as a service... and now they work.
EXACTLY LIKE I WANT.
I am not COMPLAINING... I'm just lost...
I don't see WHY they work. I'm hoping someone can point out what makes them work so I can better understand AppleScript.
Thank you in advance