Moving a file from Folder A to Folder B

Hello.

I have read through a bunch of the posts and still not ending up where I need to. Any help would be great. Macro action or AppleScript welcomed (or anything else I have yet to learn). Thank you!

Scenario:

  • Macro is triggered.
  • An Excel file is created/saved in Folder A (local_tempPath).
  • The file is edited with the necessary information.
  • The file is then moved from File A to File B (local_finalPath).

The naming convention of the file is saved to variable (local_fileName) in the beginning of the macro and used throughout.

Here is a mock up of what the bare bones version looks like:

image

Move file.kmactions (1.2 KB)

Hey Mike,

  1. Why are you creating it in one place and then moving it to somewhere else – instead of simply creating it at its final destination?

  2. Does the name change between creation and move?

-Chris

Hi Chris,

  1. It's a long reason.. We use templates of files. If my coworker ever makes an issue in their submission, it breaks the template. So I save the the file before any of information is actually inputted into the cells. And then save again when everything is done. So it doesn't break the template. The reason I need it moved is.... my team does not wait for the excel file is completed, they grab it when they see it pop for the first time (incomplete).
    So I want it saving to one folder and then when it is finalized, they can pick it up in the second folder. Does that make sense?

  2. No. Just the file.

Okay, that makes sense.

Please give me real-world file paths and a real-world file name, so I have something to test with locally.

If the paths are within the home folder you can abbreviate:

~/Dir1/Dir2/...

If you're using external drives please say so.

Also – does the destination folder exist in advance of the file being moved there?

The files are actually on a Google Drive (company wide access) but accessed through GDrive App's permissions to access GDrive folders via Finder.

And both folders will already exist.

And they would look something like this:

TEMP:
/Users/mike/Library/CloudStorage/GoogleDrive-mike@rhino.com/Shared drives/Operations/SO/WO/TS/Temp

FINAL Destination:
/Users/mike/Library/CloudStorage/GoogleDrive-mike@rhino.com/Shared drives/Operations/SO/WO/TS/Final

I can't test with Google Drive, because it no longer supports Mojave – but with your paths replicated on my system this works every time.


Download: Move a File to a New Directory v1.0.kmmacros (2.6 KB)

Macro-Image

Keyboard Maestro Export

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 10.14.6
  • Keyboard Maestro v10.2

1 Like

It worked! Actually, took some fixing, but it worked.

This is for anyone who might read and use this in the future -

The template files are saved as .xlsm (excel). The local_fileName variable doesn't actually name it with the .xlsm extension. But because the extension shows in google drive, and can not be avoided, the "Move" action needs to have the extension in it so it can pick up the file. It needs to be:

%Variable%local_tempPath%/%Variable%local_fileName%.xlsm

@ccstone Unless there is a more efficient way to handle this further up the macro.

Your example above shows the file name with the file extension:

Hello2023.xlsm

I find it difficult to believe that Google Drive is showing file extensions on macOS when there are none.

Furthermore – paths are not mutable. If a file extension is required then there IS a file extension – whether you can see it or not.

macOS can play stupid games with file extensions:

image

People who turn this setting off are just asking to have problems.

Ah yes, you are correct on all parts.

Hello2023.xlsm

Was the example I gave you but then realized the local_fileName doesn't actually have that. So I needed to add it to the end for the moving actions.

And as for turning off the "Show all filename extensions" would have been helpful on the web browser google drive (not on my desktop) but alas, it doesn't allow.

1 Like

@ccstone I am running into an issue because of the extensions, wondering if you have a thought around it.

When a person receives the spreadsheet, they receive it as an XLSM. If there is no Excel macro enabled, the person gets an error in the sheet. The reason they are all XLSM is because I thought if they were all uniform, it would be easier to manipulate (as shown in the above post). But with this error coming up for the end user, my team wants me to find a way to leave the XLS files as is and the XLSM files as is.

All this to say, I see one option:

Some action (using Regex maybe - pull characters after the . (dot)) that will pull the file extension of the file and set it to local_extension, to be used in the Move action when moving local_fileName (dot) local_extension from temp folder to final folder.

Is there something different you could think of that would work cleanly?

UPDATE: I think I figured it out. Using Split Path, I can set the extension path to a variable early in the macro and then use it again later when moving the file.

1 Like

Split Path is the simplest, easiest to use solution.

1 Like