14

I'm trying to set the position of the Messages.app chat window using AppleScript.

tell application "System Events"
    set position of window 1 of application "Messages" to {100, 100}
end tell

With this code I get an error:

error "Messages got an error: Can’t set «class posn» of window 1 to {100, 100}." 
number -10006 from «class posn» of window 1

What does that mean?

If I try the same code with Finder it works. But most of the other applications don't work.

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • 2
    The script doesn't work, because there is no `position` property in the AppleScript dictionary of the application "Messages". just replace `of application "Messages"` by `of process "Messages"`. – jackjr300 Oct 10 '12 at 20:08

3 Answers3

14
tell application "System Events"
    set position of first window of application process "Messages" to {100, 100}
end tell  

Enable Access for assistive devices to run this script.

enter image description here

Parag Bafna
  • 22,812
  • 8
  • 71
  • 144
  • 3
    Thanks for the screenshot. For any who wonders, the accessibility settings no longer look like that. Instead, you have to specify which applications are allowed access in Security & Privacy > Accessibility > Privacy. – corwin.amber May 02 '17 at 18:08
9

I found a solution. Setting the bounds of the window works. I have no idea why using the position doesn't work.

tell application "System Events"
    set friendBounds to {4289, 400, 4479, 1600}
    set chatBounds to {3583, 400, 4289, 1599}
    set bounds of window "Buddies" of application "Messages" to friendBounds
    set bounds of window "Messages" of application "Messages" to chatBounds
end tell
DrummerB
  • 39,814
  • 12
  • 105
  • 142
  • 6
    You don't need the "**System Events**" application, since the `bounds` is a property of the window in the AppleScript the dictionary of the application "**Messages**". -- "**System Events**" has no `bounds` property. You can remove the `tell application "System Events"` block, the script will also work without it. – jackjr300 Oct 10 '12 at 20:10
7

As of writing, the other solutions did not work for me on macOS 10.14 Mojave. I managed to find this solution:

tell application "System Events" to tell process "Safari"
    set position of window 1 to {0, 50}
    set size of window 1 to {600, 650}
end tell
Jonathan Berger
  • 1,043
  • 13
  • 17