File operation
Copies, moves, renames, duplicates, trashes, deletes or reveals a file or folder, or creates a new empty file with a free name.
Move path to destination
Keyboard Maestro: File CreateUnique, File DeleteDirectory, File Duplicate, File MoveOrRename, File Rename, File Reveal, File Trash
Details #
Works on files and folders by path. A leading ~ means your home folder. Paths can use variables and expressions. Choose what to do with op (action is another spelling). The name is matched ignoring case and punctuation, so moveOrRename and move or rename are the same.
copy copies
sourcetodestination. Ifdestinationis an existing folder, the copy goes inside it with its own name. Otherwisedestinationis the full new path.move is the same, but moves.
rename gives the item a new name in the same folder.
destinationis the new name. If it contains a/, only its last part is used.moveOrRename moves when
destinationis a path (it contains a/) or an existing folder, and renames otherwise.duplicate makes a copy next to the original, named
name copy.ext, thenname copy 2.extand so on. With adestinationfolder it duplicates into that folder with the same free-name rule. With adestinationthat is not a folder, that path is used as is.createUnique creates an empty file.
sourceis the wanted file name or path. Ifdestinationis given it is the folder to put it in. If the name is taken the file is calledname 2.ext,name 3.extand so on.trash moves the item to the Trash. The output is its new path in the Trash.
delete removes a file or an empty folder for good, with no Trash.
deleteDirectory removes a folder and everything in it for good.
reveal shows the item selected in a Finder window.
The output is the resulting path (for reveal, the source). It also goes into the variable named in into.
Parameters #
| Parameter | Type | Required | Values | What it does |
|---|---|---|---|---|
action | text | Another spelling of op. | ||
destination | text | Where it goes, or the new name for rename. Needed for copy, move, rename and moveOrRename. Optional for duplicate and createUnique. | ||
into | text | The variable that receives the resulting path. | ||
op | text | The operation: copy, move, rename, moveOrRename, duplicate, createUnique, trash, delete, deleteDirectory or reveal. Required. Anything else fails and lists the valid ones. | ||
overwrite | yes / no | true to replace something that is already at the destination. The default is false, and then an existing destination makes the step fail. | ||
path | text | Another spelling of source. | ||
source | text | The item to work on. Required. For createUnique it is the wanted name or path. | ||
to | text | Another spelling of destination. |
Every step also accepts label, onFailure, timeout and dryRunSafe.
Examples #
Create an empty file with a free name. This really creates a file in /tmp:
- Create a new file like “switchboard-demo.txt”
- Show “Created {{made}}”
Duplicate a file next to the original. Replace the path first, since this really copies it:
- Duplicate “notes.txt”
- Show “Made {{copyPath}}”
Gotchas #
deleteon a folder that has things in it fails and tells you to usedeleteDirectory.If the destination exists and
overwriteis off, the step fails with "already exists; set overwrite to replace it". Withoverwrite, the old item is removed first.If the destination's folder does not exist, the step fails. Folders are not created for you.
createUniquewith a bare name and nodestinationfails, because there is no folder to put it in. Give a full path or adestinationfolder.A missing source fails with "nothing at … to …".
In a dry run the step is simulated and nothing on disk changes.
intois set to an empty value so later steps still run.
See also #
Get or set a file attribute, Split path, Open Finder selection, Open file or folder