Re: Isn't there a way...
Re: Isn't there a way...
- Subject: Re: Isn't there a way...
- From: John Delacour <email@hidden>
- Date: Mon, 28 Jul 2003 00:30:45 +0100
- Mac-eudora-version: 6.0a28
At 3:08 pm -0500 27/7/03, Glenn Sugden wrote:
...to write a generic-ish 'center front window' script? I understand that
the application has to be scriptable, but when running the script (from
Script Menu), the front windows seems to (often) be taken out of focus...
When running from a script editor, it works fine...
tell application "System Events"
set front_app_name to name of front process whose visible is true and
frontmost is true
end tell
For Script menu the process will ALWAYS be System Events. You have
to use the osax to get what you want:
tell app "System Events"
set {l, t, r, b} to bounds of item 1 of (get screen list)
end
tell app ("" & (path to frontmost application))
set {x1, y1, x2, y2} to bounds of window 1
set {x, y} to {(r - (x2 - x1)) / 2, (b - (y2 - y1)) / 2}
set bounds of window 1 to {x, y, x + (x2 - x1), y + (x2 - x1)}
end
JD
tell application front_app_name
set screen_list to screen list starting with main screen
set main_screen to item 1 of screen_list
set main_screen_bounds to bounds of main_screen
set main_screen_width to (item 3 of main_screen_bounds) - (item 1 of
main_screen_bounds)
set main_screen_height to (item 4 of main_screen_bounds) - (item 2 of
main_screen_bounds)
set window_bounds to bounds of front window
set window_width to (item 3 of window_bounds) - (item 1 of
window_bounds)
set window_height to (item 4 of window_bounds) - (item 2 of
window_bounds)
set x to (main_screen_width - window_width) / 2
set y to (main_screen_height - window_height) / 2
set bounds of front window to {x, y, x + window_width, y +
window_height}
end tell
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.