Move and Replace Seems Broken, No Matter How You Script It?

This is so simple, but so maddening. I simply want to move .app files from my Download folder or Desktop into the root Applications folder, and auto-replace any old versions. I have tried this with a shell script, AppleScript, and Shortcuts – and all three fail for no clear reason I can discern.

I can move the files without replacing – but all three scripts fail if there if there is already a file in the destination folder. In Shortcuts and in the AppleScript, the script just failed with a "file already exists" error message...even with the Replace switch (Shortcuts) or the "with replacing" (AS) conditions set. In the shell script below, the -f option made no difference at all. What am I doing wrong? Surely this command doesn't require a sudo...or does it?

2023-03-11_11-11-32

And this is the error KM throws:
2023-03-11_10-45-05

Or am I just missing some subtlety in the pathname formatting of the mv command?

This can be done with KM Actions (KM can check to see if the files selected in Finder end in .app and can also check for any previous versions already in the Applications folder and delete them before copying over the new versions). It is that deleting of prior versions that will allow the copying over to take place.

To see how this could work, In the example below change the path in the first Magenta Action to a path to a test folder of your own. Then select some test .app files in Finder and run the Macro. They will be moved to the destination folder with older versions overwritten. If any of the files you select are not applications (i.e. not ending in .app) they will not be moved.

Once you are totally sure it does what you want, you could change the destination path to your Applications folder.

EXAMPLE Move and Replace Selected app Files.kmmacros (19.4 KB)

Click to Show Image of Macro

But this is potentially very dangerous (with no undo).

Personally, I would never use a Macro to move Application files as the risk of messing up Applications would outweigh the tiny inconvenience of dragging and dropping the new versions with all the inbuilt safety that standard method includes.

If you keep your Applications folder in the Dock, you can drag the files you have selected in Downloads or the Desktop onto that folder. Not so exciting, but safer :slightly_smiling_face:

Be aware that if you download an application, you need to move it with the Finder in order for the system to disable Application Translocation security. Failing to do this may cause problems.

2 Likes