Move a selected file or folder to another folder

hi, how do i make a macro that can move a selected file or folder to another pre-determined folder? thanks! -todd

Here's a good example that you should be able to adapt for your specific use case:

MACRO: [FINDER] Move Selected Finder Items to Choose Folder [Example]

Of course you will need to replace the "Choose Folder" with a "Set Variable to" and enter the full POSIX path of the target folder.

hi, that's awesome, thanks!... i downloaded the macro, but i'm embarrassed to say that i'm a little lost... can i trouble you to show me where i need to enter the full posix path of the target folder? sorry and thank you very much! -todd

I was going to show you, but then I ran across a better solution:

MACRO: Move Files Selected in Finder to Specified Folder [Example]

You just need to change this Action, to enter the POSIX path to your destination folder:

image

hi, thank you (!)... is "set parent folder to choose destination folder from" the action that i delete and replace with "set to full path of destination folder" action? if so, where do i find "set to full path of destination folder" action? (i searched for it but had no luck.) sorry for being such a novice! -todd

No. Did you see the new solution/macro I just posted above?

oh! ty! i just tried it and no luck, nothing happens. did i enter the path right? the folder " documents" inside my Documents folder purposefully has a space before it. thanks for your help! -todd (screenshot attached)

I personally don't like using spaces or any other whitespace character at the beginning of a file or folder. But if it works for you . . . (but be careful -- could cause unexpected problems). If you want to make the folder sort at the top, you can use the explanation point !

The best way to get the proper POSIX path of a file or folder is to:

  1. Select the item in the Finder.
  2. Hold down OPT key, and click on Finder menu Edit > Copy "ItemName" as pathname

Make sure you have:

  1. Enabled the Macro
  2. Enabled the Macro Group it is in
  3. Entered a valid POSIX path to an existing folder
  4. Select a file in the Finder

Then trigger the macro.
It works for me.

1 Like

it worked! (i had to do some unexpected things to enable the macro from your example) you're a genius :slight_smile: and i love the copy pathname trick! plus thanks for the ! instead of a space trick for sorting. you rock, thank you very much for your great help. -todd

1 Like

Fyi, unix paths usually require spaces in names to be escaped, or else the path must be enclosed in double quotes. At least in shell scripts, not sure KM is that strict, but I would assume so. Perhaps that’s why the macro failed for you.

This is not really correct.

Unix paths, per se, do not have any consideration for quoting or escaping, and none is required when referencing a path in a Keyboard Maestro action.

Shell commands are broken in to “arguments”, separated by white space, and also have other special characters, and so anything in a shell command that needs to be a single “argument” cannot include a white space, or if it does, that white space must be escaped or quoted. But this has nothing really to do with unix paths as such, it is simply to do with how shells typically seperate their command in to arguments. So, for example:

grep "hello there" ~/Documents

The hello there needs to be quoted (or escaped as hello\ there) so that it is treated as a single argument to the grep command, but it is not a unix path.

Similarly, unix paths used in other languages (eg perl) only need to be quoted because they are strings, and strings are contained in quotes, not because they are paths.

In visual situations, where the path is in a field, they do not generally have quoting or escaping. For example, command-shift-G in the Save As dialog takes a unix path, and that path has no quoting or escaping.

1 Like