OSX Unmount usb disk drive from Automator bash script

automatorbashscriptterminal

I have a task in automator to make my backup, it runs shell script code, lot of code is working well but the unmount command doesn't works, I don't get unmount the unit after backup.

I checked to run my command successfully from terminal, It unmounts my drive well, all fine, but when It runs from my bash script in automator It doesn't unmounts the unit, no errors, it runs well, but it doesn't unmount. 🙁

My command used is:
sudo diskutil unmountDisk disk3;

I have try with and without sudo, and I have the same problem.

I have tried diskutil eject command and same thing, it unmounts the unit typing it at hand from terminal, but from my automator shell script code it doesn't.

Any idea is very welcome.

Best Answer

When run from Automator how are you inputting your password when prompted by sudo? You're probably not being prompted if you're just running it the same way as if in Terminal.

You'll need to add some AppleScript code and run it via osascript so you're prompted for an Admin password:

osascript -e 'do shell script "sudo diskutil unmountDisk disk3" with administrator privileges'