After logging into your Mac, running a script may be useful. This article will provide an example of how to mount an encrypted disk image.

The Problem

I have an external SSD drive attached to my MacBook Pro via Thunderbolt. This is a high-performance solution that provides excellent speed and reliability. I wrote about this setup in this article.
On my external hard drive, I have an encrypted image file that I use to store family videos, photos, and important documents. The problem with this setup is that every time I reboot or log back in, the encrypted image file isn’t automatically mounted. Using the image files can cause inconvenience because some of my apps need the files.

The Solution

It is actually quite easy to automatically mount this image (or do anything else that can be scripted) when logging in. This can be done without having to install any additional software.
First, create a bash script:
The bash script is responsible for mounting the image. The IMG_FILE variable holds the path to the image file to mount. The hdiutil command mounts the image and then exits. The last line makes the script executable.
Next, create the properties list file:
This creates the file in the user’s ~/Library/LaunchAgents/ folder. This will run the mount-dmg.sh script whenever the user logs in.

Conclusion

This makes it extremely easy to run any script at login for the user. There are other ways to run scripts at login, but this method is fairly easy.
Share this article

Join the newsletter

Join thousands of satisfied readers.