Copy/paste fails

I'm trying to create a macro that copies a particular folder (A) and pastes it to within another particular folder (B), on a regular basis. A prior version of A already exists within B, which I thought would produce the standard "already exists" dialog box. Instead, the macro simply fails": "File action failed because destination already exists."

Or perhaps I'm misunderstanding that error message. Does it mean that it fails instead of producing the "already exists" dialog, or because the paths I use in the Copy File action don't make sense. To be clear, I want to copy one folder, including its contents, and paste it to within a different folder (where another version of the copied folder already resides). Those are the two paths I've entered in the Copy File action.

can you share what you got so far?

did you use the Trash action?

image
(says File, but it can delete folders as well)

image

The long pathnames make this hard to follow, but suffice to mention that they are both folders.

Can the Trash File action delete entire contents of folders? My destination folder is, I believe, a protected one and it won't do to delete it and then create a new one of the same name.

Yes.
Try it with a copy, it will just be sent to the Trashcan, not completely deleted from your computer,
and let us know how it went

Forgive my ignorance but I'm not sure what you mean by it, nor how you mean the Copy function to be implemented here.

no problem.

My destination folder is, I believe, a protected one and it won't do to delete

Meant to say:
1.- In MacOS Finder, duplicate the folder you want to send to Trash, this duplicate will be your testing playground.
2.- In Keyboard Maestro, create a new macro with just one action:
Trash folder: for the path, select the duplicated folder you just created.


3.- Run this macro, and let us know if it works

Also: ==Read this advice from Peter about using Trash vs Delete==

btw, you can resize the three windows in Keyboard Maestro and make it easier to see the paths:

Mar-25-2021 13-18-12

Thank you for your help, but I'm afraid I'm getting more confused rather than more clear. For one thing, I'm not sure what the advantage of using an AppleScript is over doing something within KM natively.

Next, I'm not sure how to adapt the script in the "Trash vs. Delete" link to my purpose. I tried changing the folder name in it to that of my target folder, but the macro doesn't do anything at all.

And, I'm not sure what you're recommending I do: copy the target folder in order to delete it? Are you thinking to delete the target folder and then create a new one of the same -- rather than just clear it of its contents -- before pasting the content I want to put there?

Sorry, but I don't see where @hello even mentions AppleScript.
IAC, if the desired automation can be done acceptably using KM non-script Actions, then I generally recommend doing so.
OTOH, there are some automations that KM cannot do without a script, or a script makes it much more efficient.

I think @hello is trying to suggest that you INSERT into your Macro the KM Action Trash Action so that if the folder you want to copy already exists in your target folder, it will first be moved to the macOS Trash:

After taking a closer look at this, I realized it is more complicated than I first thought.
So here's an example Macro to help get you started.

Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

Please let us know if it meets your needs.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

MACRO:   Trash Folder at Destination Before Copy [Example]

-~~~ VER: 1.0    2021-03-25 ~~~
Requires: KM 8.2.4+   macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))

DOWNLOAD Macro File:

Trash Folder at Destination Before Copy [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author.@JMichaelTX

PURPOSE:

  • Trash Folder at Destination Before Copy [Example]

HOW TO USE

  1. First, make sure you have followed instructions in the Macro Setup below.
  2. See the below "How to Use" Comment Action
  3. This macro is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.

MACRO SETUP

  • Carefully review the Release Notes and the Macro Actions
    • Make sure you understand what the Macro will do.
    • You are responsible for running the Macro, not me. ??
      .
      Make These Changes to this Macro
  1. Assign a Trigger to this Macro .
  2. Move this macro to a Macro Group that is only Active when you need this Macro.
  3. ENABLE this Macro, and the Macro Group it is in.
    • For more info, see KM Wiki article on Macro Activation
      .
  • REVIEW/CHANGE THE FOLLOWING MACRO ACTIONS:
    (all shown in the magenta color)
    • Set DESTINATION Folder
      • CHANGE to your Destination Folder
      • Default is iCloud Drive

REQUIRES:

  1. KM 9.0+ (may work in KM 8.2+ in some cases)
  2. macOS 10.12.6 (Sierra)+

TAGS: @Example @Copy @Folder @iCloud @Trash

==USE AT YOUR OWN RISK==

  • While I have given this a modest amount of testing, and to the best of my knowledge will do no harm, I cannot guarantee it.
  • If you have any doubts or questions:
    • Ask first
    • Turn on the KM Macro Debugger from the KM Status Menu, and step through the macro, making sure you understand what it is doing with each Action.

1 Like

I do this sort of thing regularly. So regularly that I'm working on a macro to build sync commands on the fly and save them to repeatedly run them.

At the heart of it is the built-in rsync command with an option to delete files at the target that are not in the source, which is what you're up to.

You can pop something like this into an Execute Shell Script action and be done with it:

rsync -avu --delete --stats '/Users/[user name]/Desktop/thingies/folder' '/Users/[user name]/Library/Mobile Documents/iCloud~com~barebones~bbedit/Documents'

The first run will be a copy but subsequent runs will efficiently just copy changes (very quickly). The target (the last folder named) will mirror the source.

1 Like

You would be "done with it" only if you wish to hard code both the path to the source folder and path to the destination folder.

Obviously, if you wanted to allow the user to choose the source and/or destination folder, it would require more KM Actions, and a significant change to your shell script.

My above Macro provides these choices.
I don't recommend it, but if the user wished to hard code the paths, it could be done in just two KM Actions:

image

Finally, before the user uses a shell script command like rsync, they should make sure they fully understand what it does by reviewing the appropriate documentation and other examples (like at stackoverflow.com). I would personally do this since I have no prior use or knowledge of the rsync command.

I understant that to be exactly what he specified.

Yes, I know only too well. I'm working on just such a beast and it works quite nicely. I'll post it when I've used it a bit.

Meanwhile this is what the interface looks like at the moment:

ss-861

World Backup Day Update: I've made this available on my site at the moment (where you can read the PDF) but will upload it to the forum later today.

2 Likes