2012-10-09 98 views
7

我想使用AppleScript設置Messages.app聊天窗口的位置。用AppleScript設置窗口的位置

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

有了這個代碼,我得到一個錯誤:

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

這是什麼意思?

如果我用Finder嘗試相同的代碼,它就可以工作。但大多數其他應用程序不起作用。

+2

的腳本不能正常工作,因爲沒有'應用程序「消息」的AppleScript字典position'財產。只需用'進程'消息''替換'應用程序'消息''。 – jackjr300

回答

6

我找到了解決方案。設置窗口的邊界。我不知道爲什麼使用這個職位不起作用。

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 
+3

您不需要**系統事件**應用程序,因爲'bounds'是AppleScript中窗口的屬性,即應用程序「** Messages **」的字典。 - 「**系統事件**」沒有「bounds」屬性。您可以刪除「告訴應用程序」系統事件「塊,該腳本也可以在沒有它的情況下運行。 – jackjr300

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

啓用Access for assistive devices運行此腳本。

enter image description here

+1

感謝您的截圖。對於任何奇蹟,可訪問性設置不再像這樣。相反,您必須指定允許在「安全和隱私」>「輔助功能」>「隱私」中訪問哪些應用程序。 –