Is there a way to change this script to use DropBox?

Previews only support displaying embedded images from iCloud Drive. In theory that script could be updated to allow you to select a file in Dropbox and insert a reference to it, but it would not be displayed in a Preview.