Sure thing, although this might take a moment or two to setup once you do there will be no more effort required.
The AppleScript you will need to use is:
repeat
try
do shell script "hdiutil mount '/Users/richard/Desktop/My Flash Drive/encrypted.dmg'"
on error
(* Do nothing. *)
end try
end repeat
The addition of the repeat means that this script will loop in the background only to take effect once the disk image becomes available.
Here's what to do:
1) Copy this AppleScript into the Script Editor.
2)
File > Save As... > Change 'File Format' to 'application bundle', and uncheck 'Run Only' and 'Startup Screen', and then check 'Stay Open'. > Save the file somewhere that you can keep it.
3) Quit the Script Editor.
4) Navigate to the folder in which you saved your script application bundle, and ctrl+click (right click) it. Choose 'Show Package Contents'.
5) In the
Contents folder, there will be a file called
Info.plist. Open this file using TextEdit.
6) Scroll to the very bottom of the document, and create a new line above:
</dict>
</plist>
7) Paste on to the new line:
<key>LSUIElement</key>
<true/>
8) Save this file, and quit TextEdit.
9) Reboot your Mac (this step is essential!).
10) Open System Preferences, navigate to Accounts, select 'Login Items', and then click the
+ button. Select the script application bundle.
Done! Restart your Mac (again!) for the script to come into effect. Steps 4, 5, 6, 7, 8 and 9 are all to do with making the script not appear in the Dock when it's running, but if you don't mind seeing the icon constantly you can skip these steps.
This should pretty much work, but there's the slim chance I got something wrong so if this doesn't behave how you expect it to let me know and I'll figure out a fix.
All the best, hope I solved your question.