|
|
Moving Windows with QS and AppleScript
|
|
|
|
Fresh-Faced Recruit
Join Date: Aug 2007
Status:
Offline
|
|
I wanted some hot-keys to move windows to the far edges of screens on my laptop. As such, I made some AppleScripts, and assigned them to opt-cmd-(arrows).
As an example, here is the the move_left script:
tell application "Finder"
set {disp_x1, disp_y1, disp_x2, disp_y2} to bounds of window of desktop
end tell
tell application "System Events"
set frontmostApplication to name of the first process whose frontmost is true
end tell
tell application frontmostApplication
set {x1, y1, x2, y2} to bounds of window 1
set bounds of window 1 to {disp_x1, y1, disp_x1 + x2 - x1, y2}
end tell
Unfortunately, just picking window 1 doesn't work in all applications. In Adium it results in the menu-bar icon getting moved around the screen. In Firefox, nothing happens at all.
Can somebody help me figure out how to choose the select application window correctly, so that this might work correctly? I'd greatly appreciate it, as I never even looked at AppleScript until a day ago.
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Dec 2002
Status:
Offline
|
|
You can reference the selected window with 'front window':
edit: actually this doesn't appear to work in Firefox. It does work in Adium and Safari, though. Firefox might have something goofy with what it considers the active window, I don't know.
Code:
tell application "Finder"
set {disp_x1, disp_y1, disp_x2, disp_y2} to bounds of window of desktop
end tell
tell application "System Events"
set frontmostApplication to name of the first process whose frontmost is true
end tell
tell application frontmostApplication
set {x1, y1, x2, y2} to bounds of front window
set bounds of front window to {disp_x1, y1, disp_x1 + x2 - x1, y2}
end tell
|
Travis Sanderson
|
|
|
|
|
|
|
|
Junior Member
Join Date: Mar 2000
Location: Salem, OR, USA
Status:
Offline
|
|
You've run into two problems here.
1) Not all applications include an AppleScript dictionary.
2) Just because an application does contain an AppleScript dictionary it doesn't mean all commands have been implemented or that the command you want uses the keywords you expect.
If your process is going to work I see it needing to do two things:
1) Once you have discovered frontmostApplication you will need to have "if" statements for every application you typically have open.
2) Inside each "if" block you have three choices to decide amongst.
a) The application has full "normal" AppleScript support and you will use the method you mentioned in your post.
b) The application has non-normal AppleScript support. You may be able to get the frontmost window, but it isn't known as frontmost. Maybe it will be "window -1".
c) The last resort is UI Scripting. See Apple - Software - AppleScript - GUI Scripting for instructions. Also see my post at http://forums.macnn.com/79/developer...t/#post3374191 for a working example.
For Firefox you would want to do something like
tell application "System Events"
tell process "Firefox"
tell window 1
set position to {5, 50}
set size to {300, 500} end tell end tell end tell
Let me know if you have any questions on this.
-numero
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|