A Swift 4 ‘droplet’ scripting prototype, Dropsy

One of the commonest uses of scripting systems like AppleScript is to write custom conversion and similar tools: drag and drop files onto them, and they will decode/encrypt/translate/convert/munge the contents of a file into a new one. If you want to do that in Swift 4 and are not sure where to start – or have got into difficulties trying to do so – then try this Xcode project, Dropsy.

It comes with example code that makes copies of anything which you drag and drop onto it. You can also use the Open command in the File menu to open items to ‘convert’ if you prefer.

It does this using a single small document window in which you can write progress or error information easily. Its document types are set to accept any file or folder, and can be narrowed down from there.

The main work is performed in a single function, in the ViewController, which runs whenever a document (and its window and view) are opened. This composes a suitable name to suggest for the output file, runs the File Save dialog as a sheet within the document window, then performs the copying if the user clicks on the Save button.

dropsy03

Although only example code, this shows how to perform shallow copies using FileManager: drop a folder onto the app, and it will make a shallow duplicate of the whole folder.

The project is set to be compatible with macOS El Capitan and later.

It comes with a simple explanation of what it customises, which you should find useful when adapting it for your own projects. It is freely usable in any software, including commercial products, although if you do use it, I’d be grateful for a mention in the credits.

Version 1.0 of Dropsy is available from here: Dropsy
and in Downloads above.