-
Using AppleScript to Position iChat Windows
We use instant messaging quite a bit at Highwinds. I bounce back and forth between using my laptop by itself, and using it with a secondary 22″ display. Regardless of how I’m using my laptop, I like my iChat windows to fill the laptop screen with about a 3-pixel gap between each of them. This means that when I’m on my laptop alone, its screen gets filled when I Apple-Tab to iChat, and when I’m on a two-monitor setup, the larger attached monitor display is free of chat windows and they are all present on my laptop screen so I can work while watching for chats.
My AIM and GMail buddy lists are about the same length, so I like to stack them on top of each other with half of the screen height given to each. My Highwinds buddy list is the longest, so that gets a full column to itself to the right of my AIM/GMail lists. Finally, I have my chat window occupying the rest of the right-hand side of the display. You can see this in the image below (some screen names have been obscured to protect the innocent).
Unfortunately, Apple hasn’t programmed OS X to remember the position of windows between laptop-only and display-attached configurations, which means I always have to manually move my chat windows back to the second display after I reconnect it to my laptop. This is a pain in the ass. I finally got a few minutes to write an AppleScript to do this for me automatically, presented below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
-- Get display area tell application "Finder" set displayAreaDimensions to bounds of window of desktop set widthOfDisplayArea to item 3 of displayAreaDimensions set heightOfDisplayArea to item 4 of displayAreaDimensions end tell tell application "System Events" to tell process "Dock" set dockDimensions to size in list 1 set heightOfDock to item 2 of dockDimensions end tell -- Set up desired coordinates when running iChat on the laptop monitor at 1440x900 set maximumChatWindowHeight to (heightOfDisplayArea - heightOfDock) set chatWindowWidth to 275 set padding to 3 set heightOfMenuBar to 22 set laptopPhysicalDisplayWidth to 1440 set aimCoordinates to [0, 0, chatWindowWidth, (maximumChatWindowHeight / 2) - heightOfMenuBar] set gmailCoordinates to [0, (item 4 of aimCoordinates) + (heightOfMenuBar + padding), chatWindowWidth, maximumChatWindowHeight] set highwindsCoordinates to [chatWindowWidth + padding, 0, (chatWindowWidth * 2) + padding, maximumChatWindowHeight] set chatWindowCoordinates to [(chatWindowWidth * 2) + (padding * 2), 0, laptopPhysicalDisplayWidth, maximumChatWindowHeight] -- Shift everything over by laptop display width if using a second monitor if widthOfDisplayArea is greater than laptopPhysicalDisplayWidth then set widthOfSecondaryDisplay to (widthOfDisplayArea - laptopPhysicalDisplayWidth) repeat with currentDimensions in [aimCoordinates, gmailCoordinates, highwindsCoordinates, chatWindowCoordinates] repeat with itemPosition in [1, 3] set item itemPosition of currentDimensions to ((item itemPosition of currentDimensions) + widthOfSecondaryDisplay) end repeat end repeat end if -- Position chat windows tell application "iChat" set bounds of window "AIM Buddy List" to aimCoordinates set bounds of window "myGoogleTalkAddress@gmail.com" to gmailCoordinates set bounds of window "myWorkEmailAddress@highwinds.com" to highwindsCoordinates set bounds of windows whose name contains "Chats" to chatWindowCoordinates end tell
The script is pretty simple. It grabs the screen and dock dimensions, and sets up some global variables. Then, for each of my buddy lists (AIM, GMail, and Highwinds) it sets up 4-coordinate position arrays describing the [top left x, top left y, bottom right x, bottom right y] coordinates that I want each window to end up in. Next, it checks the total display area: if the area is greater than the width of my physical laptop display, it bumps all the X coordinates over by the width of the secondary display so that the windows end up on my laptop display (since I position my laptop to the right of my secondary display). Finally, it tells iChat to position the windows, referencing each by their title bar. I group all my chats in to a single window, so the title of this window is something like “18 Chats”; as a result, I use a query-like expression to reference this window’s title.
Rather than dynamically setting the position of your chat windows, if you would prefer to move your chat windows to the positions that you want them in and have your Mac tell you what the coordinates are, you can use the script below. You can then hard-code these coordinates in to the coordinate arrays in the script above.
1 2 3 4 5 6 7 8 9 10 11 12
tell application "iChat" activate set allChatWindows to every window repeat with currentWindow in allChatWindows set windowBounds to the bounds of currentWindow set allBounds to "" repeat with bound in windowBounds set allBounds to (allBounds & bound & ",") end repeat display dialog (name of currentWindow & ": " & allBounds) end repeat end tell
Category: Uncategorized | Tags: AppleScript,Coding
2 Responses to “Using AppleScript to Position iChat Windows”
Related Posts
Recent Posts
- Speak and Spell Samples (2)
- Eulogizing the Insanely Late Steve Jobs (1)
- How to find old Airport Express/Extreme/Time Capsule firmware
- async-http-client
- Using curl with a web site secured by Rails Authenticity Token (4)
- An AppleScript to Toggle Sleep Modes
- Jamming on the Arduinome with mlrv (3)
- SammichSID Finished (1)
- Greater Orlando Hackerspace (3)
- My Arduinome Build in Pictures
