Logging Window Bounds (dimensions) with Appleccript
It's been ages since I've dealt with Applescript, so advanced apologies for screwing up terminology here.
Using the following snippet, I can resize a window
tell application "BBEdit"
activate
set the bounds of the first window to {100, 0, 700, 700}
end tell
I'm interested in using a similar statement to read and then log the bounds of the first window. I tried
tell application "BBEdit"
activate
log (the bounds of the first window)
set wSize to the bounds of the first window
log wSize
end tell
but the event log listed
(*bounds of window 1*)
each time. I was expecting something more开发者_开发知识库 like
{100, 0, 700, 700}
My eventual goal is to create a variable that contains the window bounds, and the programmatically manipulate the values. Step one is learning how to properly log the values.
So, how can I log the bounds of a window application in Apple's Script Editor.
Use get
...
tell application "BBEdit"
log (get bounds of window 1)
end tell
--> Log: (*332, 44, 972, 896*)
Try coercing it to a list and then logging that.
An important applescript rule... only tell an application to do things that are in its applescript dictionary. If a command is not in its dictionary then the application doesn't know that command and you can expect strange results (if it compiles at all). In your case the "log" command is a standard applescript command, not a BBEdit command. So when you get strange results the first thing to try is to move the "non-application" commands out of the application tell block.
Therefore try setting theBounds to (the bounds of the first window) inside the BBEdit tell block, and then logging theBounds outside of the tell block.
精彩评论