Copy any File to Specified folder

Have looked at previous posts relative to this query but still gormless.

In Finder or Forklift just want to manually select one or more files (start with 1 so I understand that :slight_smile: and copy to a folder. The destination folder is always the same folder as it is process folder.

Very basic. How do I specify in the action that the file that is selected by user is what I want to copy?

Looked at simple Copy action but do not know what to put in the copy field. Clicking the folder button will result in an individual specified file but that is not what I want. For any selection selected in Finder or Forklift is what I want.

Really basic but got me stumped.

To copy a single file selected in the Finder to a set Folder you can use the Keyboard Maestro Token %FinderSelection% in the first field of the copy Action and put the path to the folder you want to copy to in the second field.

EXAMPLE Copy Single Selected File in Finder to Folder.kmmacros (15.9 KB)

For a Macro that works with either a single selected file or multiple selected files in the Finder you can use a For Each Action. The For Each Action is a looping Action. In this case it is looking at "The Finder's Selection" and it is saying, "for each item (which you give a Variable name of your own choosing such as, Local_File) in the Finder's Selection do something".

It will loop through each file you have selected one at a time, it will set the Variable Local_File to each one of them one at a time and it will end up copying all the selected files to the destination folder.

EXAMPLE Copy Selected Files in Finder to Folder.kmmacros (16.4 KB)

3 Likes

That makes sense. So if I want this to work in say Forklift or any app in which a file is selected how would I do that? Also, I looked under Insert Variables and do not see FinderSelection. Did you just create that?

%FinderSelection% is not a Variable. It is an inbuilt Token in Keyboard Maestro. Click here for an explanation.

Someone else will be able to answer that - I don't use Forklift so, I don't know. Keyboard Maestro doesn't have pre-built Forklift Actions the way it has pre-built Finder stuff.

1 Like

That is useful to know. Have to get my head round difference between variables and tokens.

Thanks.

@Zabobon already nicely covered how to work with Finder selections, so here's how you could do the same thing with ForkLift, also with the For Each action:

Copy ForkLift Selection to Designated Folder.kmmacros (3.0 KB)

2 Likes

Great thanks. Works a treat.

1 Like

Hi All.

There is one small gotcha with the tokens %FinderSelection% and %FinderSelections% with KM v10.2.

If the selection includes a symlink, the tokens return the target file, not the symlink. I shared this with @peternlewis and he mentioned that this would be changed in a future release of KM.

An alternative is to use AppleScript:

Copy Selected Items.kmmacros (3.9 KB)

3 Likes

Yuck...

I've known that but had forgotten.

I think there's a more efficient workaround, but you have to move up to AppleScriptObjC and work with NSURLs and the file manager.

I don't have time to mess with it at the moment, so if you really want to know ask on the Script Debugger Forum.

1 Like