2

I made a program to generate contracts in bulk based on data from an .xlsx file. I originally made it for PCs, and now I'm trying to create a mac version. Everything seems to be running smoothly, but there's one method in my program that relies on win32com.client, so I need to figure something else out for this. I'm wondering if there's an analogous package for macs, or a way to perform the same basic tasks without too much of a headache. I'm open to learning a bit of AppleScript; I'm just not quite sure how to employ AppleScript in Python, or where to start looking.

Here's the method I'm working with:

def PDFconverter(self, filePath, contract):
    folder = filePath
    file_type = 'docx'
    out_folder = folder + "\\" + getIssueCode(self.GUI)
    if not os.path.exists(out_folder):
        print('Creating output folder for PDFs...')
        os.makedirs(out_folder)
        print(filePath, 'created.')
    for files in os.listdir("."):
        if files == contract:
            out_name = files.replace(file_type, r"pdf")
            in_file = os.path.abspath(folder + "\\" + files)
            out_file = os.path.abspath(out_folder + "\\" + out_name)
            word1 = client.Dispatch("Word.Application")
            doc1 = word1.Documents.Open(in_file)
            print('Exporting', out_file)
            print(' ')
            doc1.SaveAs(out_file, FileFormat=17)
            doc1.Close()
            word1.Quit()

The for loop at the bottom checks to see if each word file in the folder matches the specified contract name, and then calls client.Dispatch to open the relevant file, and saves it as a PDF.

Can someone point me in the direction of a way to accomplish this on macOS?

  • Hey - are you looking to exit out to the shell and call osascript from Python? It’s not clear what superficially we’re looking to help you with here or if you’re just wanting someone to say - yes, you can just use python on the Mac since that ships and you just need to change some syntax or calls? – bmike Sep 8 '18 at 0:55

You must log in to answer this question.

Browse other questions tagged .