0

I have a python script to read from Messages database and forward some specific new messages to specific contacts. It works but the AppleScript below to send message is making Messages.app appear.

I want it to send the message in the background without activating or un-hiding the window. Is this possible?

on run {targetBuddyPhone, targetMessage}
    tell application "Messages"
        set targetService to 1st service whose service type = iMessage
        set targetBuddy to buddy targetBuddyPhone of targetService
        send targetMessage to targetBuddy
        set visible to false --> this throws an error on terminal
    end tell
end run
  • Do you to hide it from the user, or you just want to go back to the previous window after the script? You could just use tell application "X" to activate or maybe store the frontmost window before the script and summon it afterwards. – Mateus Ribeiro Jan 8 at 16:53
  • @MateusRibeiro I always keep my messages.app app in dock minimized and open, I want it to stay there. But now it steals the focus – ggnoredo Jan 8 at 16:55
-1

You could include this code at the end of the script:


tell application "Messages"
  set miniaturized of window 1 to true
end tell

Source: https://stackoverflow.com/questions/3564160/code-for-minimizing-application-window-in-mac

  • The OP stated, "I want it to send the message in the background without activating or un-hiding the window." and while adding what you've suggested nonetheless it doesn't really answer what was asked, in reference to the first quoted sentence in this comment, "Is this possible?" as the window if already miniaturized, it is un-miniaturized when the message is sent. Your suggestion just adds another visual disturbance to the flow and not in line with "I want it to send the message in the background without activating or un-hiding the window."! – user3439894 Jan 8 at 17:18
  • @user3439894 funny story: I can't see your better ideia – Mateus Ribeiro Jan 9 at 19:11

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.