Browse the docs

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 source to destination. If destination is an existing folder, the copy goes inside it with its own name. Otherwise destination is the full new path.

  • move is the same, but moves.

  • rename gives the item a new name in the same folder. destination is the new name. If it contains a /, only its last part is used.

  • moveOrRename moves when destination is a path (it contains a /) or an existing folder, and renames otherwise.

  • duplicate makes a copy next to the original, named name copy.ext, then name copy 2.ext and so on. With a destination folder it duplicates into that folder with the same free-name rule. With a destination that is not a folder, that path is used as is.

  • createUnique creates an empty file. source is the wanted file name or path. If destination is given it is the folder to put it in. If the name is taken the file is called name 2.ext, name 3.ext and 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 #

ParameterTypeRequiredValuesWhat it does
actiontextAnother spelling of op.
destinationtextWhere it goes, or the new name for rename. Needed for copy, move, rename and moveOrRename. Optional for duplicate and createUnique.
intotextThe variable that receives the resulting path.
optextThe operation: copy, move, rename, moveOrRename, duplicate, createUnique, trash, delete, deleteDirectory or reveal. Required. Anything else fails and lists the valid ones.
overwriteyes / notrue to replace something that is already at the destination. The default is false, and then an existing destination makes the step fail.
pathtextAnother spelling of source.
sourcetextThe item to work on. Required. For createUnique it is the wanted name or path.
totextAnother 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 unique file in /tmp (really creates a file)
Do
  1. Create a new file like “switchboard-demo.txt”
  2. Show “Created {{made}}”
Open in Switchboard to try it

Duplicate a file next to the original. Replace the path first, since this really copies it:

Duplicate a file (really copies it)
Do
  1. Duplicate “notes.txt”
  2. Show “Made {{copyPath}}”
Open in Switchboard to try it

Gotchas #

  • delete on a folder that has things in it fails and tells you to use deleteDirectory.

  • If the destination exists and overwrite is off, the step fails with "already exists; set overwrite to replace it". With overwrite, the old item is removed first.

  • If the destination's folder does not exist, the step fails. Folders are not created for you.

  • createUnique with a bare name and no destination fails, because there is no folder to put it in. Give a full path or a destination folder.

  • A missing source fails with "nothing at … to …".

  • In a dry run the step is simulated and nothing on disk changes. into is 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