How to automate copying a file to dropbox

Hi
I’m new to this! I have a bit experience in coding, but nevertheless I need help, here is the task,
I would like to automate this: I create a lot of music scores, and every time I have created a score I generate a PDF of the score and save it in a local folder, with the name of the song/piece. Now I also have to copy this score to a folder with the same name in DropBox. Is it possible to automate this, so the process will start the moment a file is saved to the local folder?
Any help much appreciated!

What platform/OS are you using?

I use Monterey on a Mac Studio Max

On the assumption you don’t have a tool like Hazel or Keyboard Maestro, and assuming you sync your Dropbox folder, you can accomplish this via a Mac feature called Folder Actions.

Take a look at the Mac section of this post.

That gives you the basic premise. The next step is to make sure the parent folder names match - you’ll need to look at variables for that, but see how far you get with the first step and we can help you go from there if you need more help.

Hi
Thanks a lot! It worked fine, but there is a problem: The action will ONLY take place, if the file that I save to the folder ISN’T in the folder! So it works fine the first time, but the next time - when I save the updated music-pdf and ask my score program to replace old files, the action doesn’t run.
By the way I use Keyboard Maestro extensively every day! Does it offer a better solution?
Regards Stig

Ah, you said you were creating scores and generating PDF files for your scores, not creating AND updating them, and that is a bit of a key distinctio here I’m afraid.

Here are some options off the top of my head that you might consider.

  1. Switch to a tool like Hazel, that can identify changed files. It comes up pretty regularly on this forum for Mac users looking to automate file processing/management.
  2. Change your saving approach:
    • E.g. To include a file revision (e.g. date, sequence/version number) in the file name so it is a new file each time.
    • E.g. Delete the original and then save it/set up some other automation you can maually trigger to copy after save (e.g. via Keyboard Maestro - maybe if your music socring software is always being used just for these files, you could override the save or export and have it do additional steps like copy recently modified files to Dropbox).
    • E.g. Save the score directly in the Dropbox folder - after all if it is sync’d locally, what’s the difference to your local folder saving … none. Just ensure you have appropraite backups in place as cloud storage is not quite a backup solution as you can still delete stuff, be compromised, etc.
  3. Run a “sync”.
    • There are apps that will keep folders in sync that run in the background.
    • You could roll your own to run on a schedule (Keyboard Maestro can again run scheduled macros, command line scripts can be scheduled to do this - check out rsync) that checks for files in the score folder modified since the last time the “sync” was run and then copies any modified ones to the Dropbox folder.

I’m sure there are several other options too, but these are the ones that come to mind for me right now.

Check out Keyboard Maestro’s folder trigger.

https://wiki.keyboardmaestro.com/trigger/Folder

If you were just checking for additions or removal of files, this is arguably a more accessible way to work with folder monitoring than the OS standard folder actions approach. However, it isn’t going to recognise file changes - for that you need to look at alternatives like Hazel, or taking a manual or scheduled approach as per the above.

Hopefully that gives you some ideas.