automagica / automagica

AI-powered Smart Robotic Process Automation 🤖
https://automagica.com
3k stars 476 forks source link

Add MacOSX compatibiilty for Office-related activities #110

Open AlJohri opened 4 years ago

AlJohri commented 4 years ago

I've had some success using AppleScript / JXA (Javascript for Automation) to replicate code using win32com on MacOS.

I was able to use this approach to solve a very specific use case and create docx2pdf: https://github.com/AlJohri/docx2pdf.

The actual conversion code looks like:

const word = Application("Microsoft Word");
word.open("input.docx");
const doc = word.activeDocument;
doc.saveAs({ fileName: "output.pdf", fileFormat: "format PDF" });

As you can see, this code is very similar to the existing python code using win32com.

I think this same approach can be used for almost all of the activties provided by Automagica. For example, the append_text function uses the win32com method document.add_paragraph(text) which has an equivalent in MacOS as can be seen in the AppleScript Scripting Dictionary:

Screen Shot 2020-02-18 at 1 24 14 AM
koenvaneijk commented 4 years ago

We've put this on our roadmap.

Would need to investigate what the best way would be to call AppleScript from Python. There's appelscript https://pypi.org/project/applescript/ but it's not as integrated as win32com as in not returning Python objects but just stdout/stderr.

Any suggestions are more than welcome on this topic.

As an additional challenge, our development team currently does not have access to Apple hardware and apparently you cannot buy OSX licenses for running it in a VM (legally).