Jump to content

Recommended Posts

I've been using this applescript for a while:

 

set _message_ to "{query}"

tell application "Messages"

  set _chats_ to get every text chat

  repeat with _chat_ in _chats_

       try

            set _check_ to updated of _chat_

            set _current_ to updated of _recent_

 

            if _check_ > _current_ then

                 set _recent_ to _chat_

            end if

       on error

            set _recent_ to _chat_

       end try

  end repeat

  send _message_ to _recent_

end tell

 

But unfortunately with El Capitan it started sending messages to seemingly random people, certainly not the last one I received a message from. I am looking for a way to modify this script such that it will send _message_ to the last person I either sent a message to or received a message from (as if I opened the app, selected the conversation that appears first and texted them _message_)

 

Such a script would be incredibly useful, especially when paired with Alfred, allowing one to hold a conversation over text while operating another app in full screen.

 

Any help is greatly appreciated

Link to post

I've been using this applescript for a while:

 

set _message_ to "{query}"

tell application "Messages"

  set _chats_ to get every text chat

  repeat with _chat_ in _chats_

       try

            set _check_ to updated of _chat_

            set _current_ to updated of _recent_

 

            if _check_ > _current_ then

                 set _recent_ to _chat_

            end if

       on error

            set _recent_ to _chat_

       end try

  end repeat

  send _message_ to _recent_

end tell

 

But unfortunately with El Capitan it started sending messages to seemingly random people, certainly not the last one I received a message from. I am looking for a way to modify this script such that it will send _message_ to the last person I either sent a message to or received a message from (as if I opened the app, selected the conversation that appears first and texted them _message_)

 

Such a script would be incredibly useful, especially when paired with Alfred, allowing one to hold a conversation over text while operating another app in full screen.

 

Any help is greatly appreciated

 

Hi there,

 

Could you please fill in your Powerpack email address in your forum profile first? We'll then be happy to help you out :)

 

Cheers,

Vero

Link to post

Hi there,

 

Could you please fill in your Powerpack email address in your forum profile first? We'll then be happy to help you out :)

 

Cheers,

Vero

 

I updated my profile. Also, just to be clear, the issue is really around the inability to access properties of objects using apple script. I made a stack exchange thread here: http://apple.stackex...ect-not-working

which has unfortunately received no replies.

 

If I could figure out how to get the "updated" property from each chat the above script would work perfectly. The only reason the above script even runs is because of the try statement (every iteration errors).

 

 

I hope that you can still help though since if this was fixed it would make a really great workflow.

Link to post

Unfortunately, the answer to your question is that it's currently impossible to do because the AppleScript support in  Messages.app is broken.
 
Your code should work, but Messages.app isn't giving you the text chat objects it says it does:

tell application "Messages" to return properties of every chat

produces:

{{class:item}, {class:item}, {class:item}, {class:item}, ...}

which is just a bunch of empty records.

Compare it with Safari:

tell application "Safari" to return properties of every window

which returns:

{{document:document "Reply to Message - Workflow Help & Questions - Alfred App Community Forum" of application "Safari", closeable:true, zoomed:true, class:window, index:1, visible:true, name:"Reply to Message - Workflow Help & Questions - Alfred App Community Forum", modal:false, miniaturizable:true, titled:true, id:23277, miniaturized:false, floating:false, resizable:true, bounds:{1263, 761, 2543, 1547}, current tab:tab 4 of window id 23277 of application "Safari", zoomable:true}, ...}
Link to post

 

Unfortunately, the answer to your question is that it's currently impossible to do because the AppleScript support in  Messages.app is broken.

 

Your code should work, but Messages.app isn't giving you the text chat objects it says it does:

tell application "Messages" to return properties of every chat

produces:

{{class:item}, {class:item}, {class:item}, {class:item}, ...}

which is just a bunch of empty records.

Compare it with Safari:

tell application "Safari" to return properties of every window

which returns:

{{document:document "Reply to Message - Workflow Help & Questions - Alfred App Community Forum" of application "Safari", closeable:true, zoomed:true, class:window, index:1, visible:true, name:"Reply to Message - Workflow Help & Questions - Alfred App Community Forum", modal:false, miniaturizable:true, titled:true, id:23277, miniaturized:false, floating:false, resizable:true, bounds:{1263, 761, 2543, 1547}, current tab:tab 4 of window id 23277 of application "Safari", zoomable:true}, ...}

 

 

Oh wow. I had no idea that major releases could have such significant issues. Thanks for the heads up and hopefully they'll fix this in a reasonable time scale.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...