Actions#
This page shows the specifics of each action. For basic action usage and options have a look at the Rules section.
confirm#
Ask for confirmation before continuing.
Examples
Confirm before deleting a duplicate
rules:
- name: "Delete duplicates with confirmation"
locations:
- ~/Downloads
- ~/Documents
filters:
- not empty
- duplicate
- name
actions:
- confirm: "Delete {name}?"
- trash
copy#
Copy a file or dir to a new location.
If the specified path does not exist it will be created.
Parameters: |
|
---|
The next action will work with the created copy.
Examples:
Copy all pdfs into ~/Desktop/somefolder/
and keep filenames
rules:
- locations: ~/Desktop
filters:
- extension: pdf
actions:
- copy: "~/Desktop/somefolder/"
Use a placeholder to copy all .pdf files into a "PDF" folder and all .jpg files into a "JPG" folder. Existing files will be overwritten.
rules:
- locations: ~/Desktop
filters:
- extension:
- pdf
- jpg
actions:
- copy:
dest: "~/Desktop/{extension.upper()}/"
on_conflict: overwrite
Copy into the folder Invoices
. Keep the filename but do not overwrite existing files.
To prevent overwriting files, an index is added to the filename, so somefile.jpg
becomes somefile 2.jpg
.
The counter separator is ' '
by default, but can be changed using the counter_separator
property.
rules:
- locations: ~/Desktop/Invoices
filters:
- extension:
- pdf
actions:
- copy:
dest: "~/Documents/Invoices/"
on_conflict: "rename_new"
rename_template: "{name} {counter}{extension}"
delete#
Delete a file from disk.
Deleted files have no recovery option!
Using the Trash
action is strongly advised for most use-cases!
Examples:
Delete old downloads.
rules:
- locations: "~/Downloads"
filters:
- lastmodified:
days: 365
- extension:
- png
- jpg
actions:
- delete
Delete all empty subfolders
rules:
- name: Delete all empty subfolders
locations:
- path: "~/Downloads"
max_depth: null
targets: dirs
filters:
- empty
actions:
- delete
echo#
Prints the given message.
This can be useful to test your rules, especially in combination with placeholder variables.
Parameters: |
|
---|
Examples:
rules:
- name: "Find files older than a year"
locations: ~/Desktop
filters:
- lastmodified:
days: 365
actions:
- echo: "Found old file"
Prints "Hello World!" and filepath for each file on the desktop:
rules:
- locations:
- ~/Desktop
actions:
- echo: "Hello World! {path}"
This will print something like Found a ZIP: "backup"
for each file on your desktop
rules:
- locations:
- ~/Desktop
filters:
- extension
- name
actions:
- echo: 'Found a {extension.upper()}: "{name}"'
Show the {relative_path}
and {path}
of all files in '~/Downloads', '~/Desktop' and their subfolders:
rules:
- locations:
- path: ~/Desktop
max_depth: null
- path: ~/Downloads
max_depth: null
actions:
- echo: "Path: {path}"
- echo: "Relative: {relative_path}"
macos_tags#
Add macOS tags.
Parameters: |
|
---|
The color can be specified in brackets after the tag name, for example:
macos_tags: "Invoices (red)"
Available colors are none
, gray
, green
, purple
, blue
, yellow
, red
and
orange
.
Examples:
rules:
- name: "add a single tag"
locations: "~/Documents/Invoices"
filters:
- name:
startswith: "Invoice"
- extension: pdf
actions:
- macos_tags: Invoice
Adding multiple tags ("Invoice" and "Important")
rules:
- locations: "~/Documents/Invoices"
filters:
- name:
startswith: "Invoice"
- extension: pdf
actions:
- macos_tags:
- Important
- Invoice
Specify tag colors
rules:
- locations: "~/Documents/Invoices"
filters:
- name:
startswith: "Invoice"
- extension: pdf
actions:
- macos_tags:
- Important (green)
- Invoice (purple)
Add a templated tag with color
rules:
- locations: "~/Documents/Invoices"
filters:
- created
actions:
- macos_tags:
- Year-{created.year} (red)
move#
Move a file to a new location.
The file can also be renamed. If the specified path does not exist it will be created.
If you only want to rename the file and keep the folder, it is
easier to use the rename
action.
Parameters: |
|
---|
The next action will work with the moved file / dir.
Examples:
Move all pdfs and jpgs from the desktop into the folder "~/Desktop/media/". Filenames are not changed.
rules:
- locations: ~/Desktop
filters:
- extension:
- pdf
- jpg
actions:
- move: "~/Desktop/media/"
Use a placeholder to move all .pdf files into a "PDF" folder and all .jpg files into a "JPG" folder. Existing files will be overwritten.
rules:
- locations: ~/Desktop
filters:
- extension:
- pdf
- jpg
actions:
- move:
dest: "~/Desktop/{extension.upper()}/"
on_conflict: "overwrite"
Move pdfs into the folder Invoices
. Keep the filename but do not overwrite existing files. To prevent overwriting files, an index is added to the filename, so somefile.jpg
becomes somefile 2.jpg
.
rules:
- locations: ~/Desktop/Invoices
filters:
- extension:
- pdf
actions:
- move:
dest: "~/Documents/Invoices/"
on_conflict: "rename_new"
rename_template: "{name} {counter}{extension}"
python#
Execute python code.
Parameters: |
|
---|
Examples:
A basic example that shows how to get the current file path and do some printing in a
for loop. The |
is yaml syntax for defining a string literal spanning multiple lines.
rules:
- locations: "~/Desktop"
actions:
- python: |
print('The path of the current file is %s' % path)
for _ in range(5):
print('Heyho, its me from the loop')
rules:
- name: "You can access filter data"
locations: ~/Desktop
filters:
- regex: '^(?P<name>.*)\.(?P<extension>.*)$'
actions:
- python: |
print('Name: %s' % regex["name"])
print('Extension: %s' % regex["extension"])
Running in simulation and yaml aliases:
my_python_script: &script |
print("Hello World!")
print(path)
rules:
- name: "Run in simulation and yaml alias"
locations:
- ~/Desktop/
actions:
- python:
code: *script
run_in_simulation: yes
You have access to all the python magic -- do a google search for each filename starting with an underscore:
rules:
- locations: ~/Desktop
filters:
- name:
startswith: "_"
actions:
- python: |
import webbrowser
webbrowser.open('https://www.google.com/search?q=%s' % name)
rename#
Renames a file.
Parameters: |
|
---|
The next action will work with the renamed file / dir.
Examples:
rules:
- name: "Convert all .PDF file extensions to lowercase (.pdf)"
locations: "~/Desktop"
filters:
- name
- extension: PDF
actions:
- rename: "{name}.pdf"
rules:
- name: "Convert **all** file extensions to lowercase"
locations: "~/Desktop"
filters:
- name
- extension
actions:
- rename: "{name}.{extension.lower()}"
shell#
Executes a shell command
Parameters: |
|
---|
Returns
{shell.output}
(str
): The stdout of the executed process.{shell.returncode}
(int
): The returncode of the executed process.
Examples:
rules:
- name: "On macOS: Open all pdfs on your desktop"
locations: "~/Desktop"
filters:
- extension: pdf
actions:
- shell: 'open "{path}"'
symlink#
Create a symbolic link.
Parameters: |
|
---|
Only the local filesystem is supported.
trash#
Move a file or dir into the trash.
Examples:
rules:
- name: Move all JPGs and PNGs on the desktop which are older than one year into the trash
locations: "~/Desktop"
filters:
- lastmodified:
years: 1
mode: older
- extension:
- png
- jpg
actions:
- trash