organize-tool Documentation

repository·main·Indexed 25 days ago

https://github.com/tfeldmann/organize

A command-line file management automation tool for sorting, renaming, moving, and cleaning up files based on custom rules. It provides an open-source alternative to desktop automation apps, featuring a CLI for rule execution, simulation, and configuration management. Supported actions include move, copy, delete, trash, rename, shell commands, Python scripts, and macOS tags.

Tokens
12.4K
Snippets
55
Records
62
Agent score
83%

What's inside organize-tool

  1. Structure an organize configuration file

    main

    An organize configuration file can be written in YAML or JSON. The top-level element must be a dictionary containing a rules key, which holds a list of rule objects. Each rule object must include locations and actions keys.

    Rules are processed in order: from top to bottom for rules, then top to bottom for locations, then top to bottom for filters, and finally top to bottom for actions.

    rules:
      - locations: "~/Desktop"
        actions:
          - echo: "Hello World!"
  2. Filter rules using tags

    main

    You can categorize rules in your YAML configuration using tags. Use the --tags and --skip-tags CLI options to include or exclude specific groups of rules. These options accept a comma-separated list of tags.

    Rule Configuration Example:

    rules:
      - name: My first rule
        actions:
          - echo: "Hello world"
        tags:
          - debug
          - fast

    CLI Usage:

    organize sim --tags=debug,foo --skip-tags=slow

    Special Tags:

    • always: Rules with this tag will always run unless --skip-tags=always is used.
    • never: Rules with this tag will never run unless --tags=never is used.
  3. Use relative locations and change working directory

    main

    Locations can be defined as relative paths (e.g., locations: "docs"), which are relative to the current working directory. You can control the base directory for these relative paths using the --working-dir CLI flag when running the sim command.

    # huge-pic-warner.yaml
    rules:
      - locations: "docs" # relative to working dir
        filters:
          - extension: jpg
          - size: ">3 MB"
        actions:
          - echo: "Warning - huge pic found!"
    organize sim huge-pic-warner.yaml --working-dir=some/other/dir/
  4. Use environment variables in locations

    main

    You can inject environment variables into location paths using two syntaxes. When using the {env} syntax, ensure the path is enclosed in quotes.

    • {env.VARIABLE_NAME}
    • $VARIABLE_NAME
    rules:
      - locations:
          # via {env} - quotes are required
          - "{env.MY_FOLDER}"
    
          # via $
          - "$MY_FOLDER"
    
          # combined with options
          - path: "{env.OTHER_FOLDER}/Inbox/Invoices"
            max_depth: null
        actions:
          - echo: "{path}"
  5. Simulate file organization with organize sim

    main
    Before applying changes to your actual files, use the organize sim command. This simulates the execution of your rules and shows you what would happen (e.g., which files would be moved or renamed) without actually touching your filesystem.
    organize sim
  6. Migrate from v1 to v2

    main

    When upgrading from version 1 to version 2, apply the following changes to your configuration:

    Folders to Locations

    • Rename folders to locations.
    • Glob syntax (e.g., /Docs/**/*.png) and exclamation mark exclude syntax (e.g., ! ~/Desktop/exclude) are no longer supported in locations. See Location options for valid syntax.
    • All keys (filter names, action names, option names) must be lowercase.

    Placeholders (Jinja Template Engine)

    • {basedir} is no longer available.
    • Replace undocumented placeholders with Jinja-compatible syntax. For example, to format a date:
      • Old: "{created.year}-{created.month:02}-{created.day:02}"
      • New: "{created.strftime('%Y-%m-%d')}"
    • To left pad numbers, use Jinja formatting:
      • "{'%02d' % your_variable}" or "{ '{:02}'.format(your_variable) }"

    Filters

    • filename is now name.
    • filesize is now size.
    • created and lastmodified no longer accept a timezone; they use the local timezone by default.
    • extension's lower and upper are now functions: use "{extension.upper()}" and "{extension.lower()}".

    Actions (Conflict Resolution)

    copy, move, and rename actions now use new parameters for conflict resolution. If you previously used these without arguments, no change is required. If you used them to manage conflicts, you must migrate to on_conflict and rename_template.

    Settings

    • The system_files setting has been removed. To include system files, overwrite system_exclude_files and system_exclude_dirs with an empty list [] within your location configuration.
    # Example: Migrating move action from v1 to v2
    # v1 style:
    rules:
      - folders: ~/Desktop
        filters:
          - extension: pdf
        actions:
          - move:
              dest: ~/Documents/PDFs/
              overwrite: false
              counter_seperator: "-"
    
    # v2 style:
    rules:
      - locations: ~/Desktop
        filters:
          - extension: pdf
        actions:
          - move:
              dest: ~/Documents/PDFs/
              on_conflict: rename_new
              rename_template: "{name}-{counter}{extension}"
  7. Locate the configuration file

    main

    Use the show command to find where your configuration file is located. Use the --path flag to see the absolute path to the default configuration file.

    organize show             # opens the folder containing the config
    organize show --path       # shows the full path to the default config
    organize show --path
  8. Run organize with volume mounts

    main

    When running the container, ensure you mount your data directory and your configuration file correctly.

    Warning: Since organize moves files, if you move a file to a directory that is not persisted via a volume mount, the file will be lost when the container stops.

    To run a basic setup, mount your local configuration file to /config/config.yml and your data directory to /data inside the container.

    docker run -v ./docker-conf.yml:/config/config.yml -v .:/data organize run
  9. Target directories instead of files

    main

    By default, rules target files. To target folders instead, set targets: "dirs".

    When targeting directories, filters adjust their behavior automatically. For example, the size filter will return the sum of the sizes of all files within the folder. Note that some filters (like exif or filecontent) are file-specific and will return an error if applied to a directory.

    rules:
      - locations: ~/Desktop
        targets: dirs
        actions: ...
  10. Run or simulate configuration rules

    main

    Use run to execute the rules defined in your configuration, or sim to simulate them (dry run). You can specify a specific configuration file and a working directory.

    # Run/simulate default config
    organize sim
    organize run
    
    # Run/simulate a specific config file
    organize sim [FILE]
    organize run [FILE]
    
    # Run/simulate a specific config file in a specific directory
    organize sim [FILE] --working-dir=~/Documents
    organize sim [FILE] --working-dir=~/Documents