0

Computer A: Has a script which, when run, will return the content of a iMessage sent to the computer (from the Messages.app)

Computer B: Has a script which will display the content of the iMessage received on Computer A

This is the desired result. Currently the way I have it working is all on one machine, so the computer that receives the message is able to display it. I have tried running the script on Computer B with the script pointing to the path of the message file from Computer A via Mac file sharing. The problem with this is the file sharing seems very intermittent, it often disconnects or doesn't grab the up to date information. When it's all running on one machine, it's instant, no delays.

What alternatives are there for transferring the data between the 2 computers. Can Computer B trigger Computer A to run the script that gets the data, and then somehow have it sent to the script on Computer B?

Thanks for any help!

If it's not clear, let me know and I'll try to elaborate more

jww
  • 97,681
  • 90
  • 411
  • 885
srb7
  • 337
  • 2
  • 9
  • 1
    How about running a small Python webservice? – Standard Sep 27 '19 at 11:01
  • How would this work? I'm trying to avoid it going outside of our local network if possible – srb7 Sep 27 '19 at 11:12
  • 2
    you can build a webservice in your local net and send http requests like you do in the "real" internet. – Standard Sep 27 '19 at 11:17
  • How would I go about doing this? I've not worked much with web languages, and only really just started on Python - what's the best way to look up how to do this? Thanks for your help – srb7 Sep 27 '19 at 11:18
  • 2
    something like this https://stackoverflow.com/a/41050031/2836172, would be a little bit easier than a web framework. @robscotts answer is also good. – Standard Sep 27 '19 at 11:22

1 Answers1

2

I suggest you look into the 'pika' module and RabbitMQ message broker. More info on their tutorial page. https://www.rabbitmq.com/tutorials/tutorial-one-python.html

A free and simple RabbitMQ server can be found here: https://www.cloudamqp.com/

robscott
  • 91
  • 7
  • I'll read though the documentation now, but are you able to tell me if someone needs to manually run the script on both machines for it to work? If Computer A has the data, does someone has to initiate the send script and then someone go to Computer B to initiate the receive script? Or does the receive script have a way of triggering the send script on its own? – srb7 Sep 27 '19 at 11:14
  • You basically leave the receiving script on. It's basically a listener (you just start the task in terminal or if you want more advanced stuff look into cronjobs or something that will start in background at startup) that will wait for the message from appropriate queue you send the message to. Not sure about the file size though, for simple text messages or even images it worked fine for me. For sending, it might be good to have some automated script if needed be that will convert the message you want to send to an appropriate format and send it to the queue. – robscott Sep 27 '19 at 11:17
  • So the person who runs the script that sends the message, can they still do this on the receiving computer? Or does the send script have to be run from the computer containing the source data? – srb7 Sep 27 '19 at 11:19
  • They can be totally separate and can be run on the same computer, but it'd be good to have separate queues in that case to distinguish the messages received. In both cases the scripts have to be run from the source script of course, depending on your project structure. If you want more complex send and receive mechanic, I'd use multithreading. – robscott Sep 27 '19 at 11:21
  • I'd just go quickly through the tutorial, copy and paste the code and play with it to see if it fits your needs, and might work as a prototype. I think what you're looking for is message broking, but I might be wrong. – robscott Sep 27 '19 at 11:25
  • As a slight tangent from this question - is there a way to run a script on one computer from another computer remotely? – srb7 Sep 27 '19 at 11:31
  • Without some listener script that waits for a message? Remote desktop. – robscott Sep 27 '19 at 11:37
  • So I was able to run the script remotely by going into terminal and accessing the remote machine by SSH, then navigating through until the desktop where the py file is and running it. Rather than doing this through terminal, how can I embed this into my script so 1 script can be run which will do this SSH command? Hope that makes sense – srb7 Sep 27 '19 at 12:21
  • You're going offtopic relative to the original question + you've stated the problem in the question that can be easily googled. https://stackoverflow.com/questions/3586106/perform-commands-over-ssh-with-python#3586168 – robscott Sep 27 '19 at 17:47