QS, AppleScript and moving windows
A 15” laptop has a relatively small display, so I find myself routinely wanting to put a window all the way to one edge or the other, to help maximize the use of this.
I decided that this should be simple, something along the lines of ^⌥⌘← to slam a window to the left edge of my screen and so on.
There were a few hitches, but I did it as follows:
First I made some scripts:
move_left
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
tell process frontmostApplication
tell window 1
set {x1, y1} to position
set position to {disp_x1, y1}
end tell
end tell
end tell
move_right
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
tell process frontmostApplication
tell window 1
set {x1, y1} to position
set {x_off, y_off} to size
set position to {disp_x2 - x_off, y1}
end tell
end tell
end tell
move up
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
set disp_y1 to disp_y1 + 22
tell process frontmostApplication
tell window 1
set {x1, y1} to position
set position to {x1, disp_y1}
end tell
end tell
end tell
move down
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
tell process frontmostApplication
tell window 1
set {x1, y1} to position
set {x_off, y_off} to size
set position to {x1, disp_y2 - y_off}
end tell
end tell
end tell
And at the suggestion of Alex L.
move center
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
set disp_y1 to disp_y1 + 22
tell process frontmostApplication
tell window 1
set {x1, y1} to position
set {x_off, y_off} to size
set position to {disp_x1 + (disp_x2 - x_off) / 2, disp_y1 + (disp_y2 - y_off) / 2}
end tell
end tell
end tell
I added these to QS hotkeys, and used the same technique to make windows do incremental moves as well.
Credit to the MacNN Forums, who helped me find a useful answer in this thread.
Follow-up: Zachary Cohen wrote a correction: Seems like a cool little article, but you need to make sure that Access for assistive devices is turned on. You do this by going to “System Preferences” then selecting the “Universal Access” from the options. Then click the click the checkbox at the bottom “Enable access for assistive devices” then these scripts should work.
Growl, Mail.app and AppleScript
I wanted a simple system that would notify me whenever I received an e-mail from somebody “important”, but not for every new message that hit my inbox.
I tried GrowlMail and Mail.Appetizer, but found them both unsatisfactory. I finally decided that what I really wanted was a growl message to appear for messages from selected recipients. Something with the name and the subject of the e-mail, like this:

Fortunately, it turned out to be reasonably simple.
First, I opened up Address Book, and made sure that the important people were all listed in appropriate groups and correct e-mail addresses.
Having done that, I opened Mail.app, and added a rule:
Description: Growlbut ho, you say, that script does not exist! Never fear, then I loaded up Script Editor and created MailScript.scpt as follows:
If any of the following conditions are met:
Sender is member of Group: Clients
Sender is member of Group: Family
Sender is member of Group: InsideSystems
Perform the following actions:
Run AppleScript: ~/Library/Scripts/Applications/Mail/MailScript.scpt
on perform_mail_action(info)
tell application "Mail"
set selectedMessages to |SelectedMessages| of info
set theRule to |Rule| of info
repeat with eachMessage in selectedMessages
set theSubject to subject of eachMessage
set theSender to sender of eachMessage
tell application "GrowlHelperApp"
set the allNotificationsList to ¬
{"New Mail"}
set the enabledNotificationsList to ¬
{"New Mail"}
register as application ¬
"MailScript" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Mail"
notify with name ¬
"New Mail" title ¬
"New Mail from " & theSender description ¬
theSubject application name "MailScript"
end tell
end repeat
end tell
end perform_mail_action
Now, this was the first time I ever did anything in AppleScript, so it’s quite possible there is a much better way to do all of this. As it stands, I simply glued together some sample code from Growl and some sample code from this hint on the excellent MacOSXHints.com, and it appears to work as desired.
Finally, I went into the growl prefpane, and set the priority and stickiness, so that these messages would stay on my screen even if I happened to be otherwise occupied when they came in.
Voila! Nothing spectacularly complex, but it’s a nice example of what I like about Apple. Everything’s easy to use out of the box, but when I dreamed up a random feature, I was able to implement it in a short period of time, despite having never even used their glue language before.
Hopefully somebody else would like this feature too!