kat
kat

Reputation: 23

How to attach multiple .dmg files present in a folder using python in macOS

Multiple .dmg files are present in a particular folder,Using python how could i mount those .dmg files iteratively. I tried the following code

    import os
    path = '/Users/kat/Desktop/pro'
    os.chdir(path)
    for i in os.scandir(path):
     print(i)
     os.system("hdiutil attach i")

But i get "hdiutil" command not found error.Any suggestions would be helpful.

Upvotes: 2

Views: 155

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207485

I think you want something more like this:

import os, glob

os.chdir('/Users/kat/Desktop/pro')

for i in glob.glob("*.dmg"): 
    print(i) 
    os.system(f'hdiutil attach "{i}"')

Python "f-strings" are described here.

Upvotes: 1

user3409217
user3409217

Reputation: 626

You have a typo in your code. The command is actually hdiutil.

Upvotes: 0

Related Questions