Auto-magic file organisation for your machines. :open_file_folder:

Switchboard

GitHub Actions Status GitHub Actions Status Go Report Card Homebrew Downloads Downloads GitHub go.mod Go version of a Go module GoDoc reference example GitHub stars GitHub forks

Gomerge logo

Description

Do you ever get annoyed that your Downloads folder gets cluttered with all types of files? Do you wish you could automatically organise them into seperate, organised folders? Switchboard is a tool to help simplfy file organization on your machine/s.

Switchboard works by monitoring a directory you provide (or list of directories), and uses file system notifications to move a matched file to the appropriate destination directory of your choosing.

See the video below as example. Here, I give switchboard a path to watch, a destination where I want matched files to move to, and the file extension of the type of files I want to move.

asciicast

You can also visit https://goswitchboard.io/ for all your documentation needs, news, and updates!

Installation

You can install switchboard pre-compiled binary in a number of ways.

Homebrew
brew tap Cian911/switchboard
brew install switchboard

// Check everything is working as it should be
switchboard -h

You can also upgrade the version of switchboard you already have installed by doing the following.

brew upgrade switchboard
Docker
docker pull ghcr.io/cian911/switchboard:${VERSION}

docker run -d -v ${SRC} -v ${DEST} ghcr.io/cian911/switchboard:${VERSION} watch -h
Go Install
go install github.com/Cian911/switchboard@${VERSION}
Manually

You can download the pre-compiled binary for your specific OS type from the OSS releases page. You will need to copy these and extract the binary, then move it to you local bin directory. See the example below for extracting a zipped version.

curl https://github.com/Cian911/switchboard/releases/download/${VERSION}/${PACKAGE_NAME} -o ${PACKAGE_NAME}
sudo tar -xvf ${PACKAGE_NAME} -C /usr/local/bin/
sudo chmod +x /usr/local/bin/switchboard

Quick Start

Using switchboard is pretty easy. Below lists the set of commands and flags you can pass in.

Run the switchboard application passing in the path, destination, and file type you'd like to watch for.

Usage:
   watch [flags]

Flags:
      --config string        Pass an optional config file containing multiple paths to watch.
  -d, --destination string   Path you want files to be relocated.
  -e, --ext string           File type you want to watch for.
  -h, --help                 help for watch
  -p, --path string          Path you want to watch.
      --poll int             Specify a polling time in seconds. (default 60)

To get started quickly, you can run the following command, passing in the path, destination, and file extenstion you want to watch for. See the example below.

switchboard watch -p /home/user/Downloads -d /home/user/Movies -e .mp4

We highly recommend using absolute file paths over relative file paths. Always include the . when passing the file extension to switchboard.

And that's it! Once ran, switchboard will start observing the user downloads folder for mp4 files added. Once it receives a new create event with the correct file extension, it will move the file to the users movies folder.

Important Notes

Polling

We set a high polling time on switchboard as in some operating systems we don't get file closed notifications. Therefore switchboard implements a polling solution to check for when a file was last written to. If the file falls outside the time since last polled, the file is assumed to be closed and will be moved to the destination directory. This obviously is not ideal, as we can't guarentee that a file is actually closed. Therefore the option is there to set the polling interval yourself. In some cases, a higher polling time might be necessary.

Absolute File Path

As you might have noticed in the example above, we passed in the absolute file path. While relative file paths will work too, they have not been tested in all OS systems. Therefore we strongly recommend you use absolute file paths when running switchboard.

File Extenstion

You may have also noticed in the above example, we used .mp4 including the prefixed .. This is important, as switchboard will not match file extenstions correctly if the given --ext flag does not contain the ..

Owner
Cian Gallagher
Senior Software Engineer @zendesk
Cian Gallagher
Comments
  • Add polling

    Add polling

    This PR adds a queue/polling system.

    I encountered a bug wherein downloading files would trigger a CREATE event initially, but the operation would not have completed. This lead to the file being moved to the consumer destination, but being invalid.

    This PR introduces a queue/polling system. Events will be added to a queue, wherein a poller will check every x number of seconds when the file was last modified. If the file was modified within the last x number of seconds, we will continue polling, otherwise, we can assume operation has completed, and the file is valid.

    This does not obviously cover all scenarios, for example, you might be downloading a file and halfway through you may loose internet connectivity. In this instance, the file will be moved, and may very well be invalid. That being said, I believe this change will greatly improve switchboard compared to how it currently stands.

  • feature request: inotify

    feature request: inotify

    On Linux, manually polling is not needed. Have you looked into inotifywait or something like https://github.com/xyproto/recwatch?

    Switchboard is a neat idea!

  • feature request: Add priority order to watchers

    feature request: Add priority order to watchers

    Each watcher should have a changeable priority which would denote which watcher should process an event in the case that multiple watchers match the same event. Take the example below.

    I have the following config for switchboard:

    pollingInterval: 10
    watchers:
      - path: "/home/cian/Downloads"
        destination: "/home/cian/Documents"
        ext: ".txt"
      - path: "/home/cian/Downloads"
        destination: "/home/cian/Documents/Reports"
        ext: ".txt"
        pattern: "(?i)(financial-report-[a-z]+-[0-9]+.txt)"
      - path: "/home/cian/Downloads"
        destination: "/home/cian/Videos"
        ext: ".mp4"
    

    In the event that I save a txt file that matches the first two watchers, we encounter a race condition between the two as to which will process the event first.

    I propose adding a priority attribute to switchboard which will denote the order in which events should be processed by watchers, should multiple watchers be capable of matching the same event. A new config might look like this:

    pollingInterval: 10
    watchers:
      - path: "/home/cian/Downloads"
        destination: "/home/cian/Documents"
        ext: ".txt"
        priority: 1
      - path: "/home/cian/Downloads"
        destination: "/home/cian/Documents/Reports"
        ext: ".txt"
        pattern: "(?i)(financial-report-[a-z]+-[0-9]+.txt)"
        priority: 2
    

    1 in this case should be the lowest priority, which all watcher will default to, and a higher priority ascending from that 2, 3, 4...

  • feature request: Support for specific event types

    feature request: Support for specific event types

    As a user, I want to be able to configure and watch for specific event types. For example, I should have the ability to watch for CREATE events specifically that match a file extension/pattern, or DELETE events as example.

  • feature request: Add conditional logging

    feature request: Add conditional logging

    Add support for conditional logging - User should be able to choose the log level they want for switchboard via a flag passed to the watch command.

    As example:

    switchboard watch --config -log verbose
    

    Loging should be disabled by default otherwise - this remove all the noise when being run.

  • wip: Add IN_CLOSE_* event support for linux systems

    wip: Add IN_CLOSE_* event support for linux systems

    ~This is currently a WIP branch that contains work today adding IN_CLOSE_WRITE support for linux systems.~

    This PR adds support for IN_CLOSE_WRITE events on Linux systems.

    Todo:

    • [x] Add support for IN_CLOSE_* events
    • [x] Keep polling implementation - but make it use optional only on Linux systems.
    • [x] Add/Update tests
  • SWB: Add support for Docker

    SWB: Add support for Docker

    Description

    This PR adds support for Docker.

    Changes

    I have wanted to add a Docker example and use-case for the project. The original intention was to have switchboard run a a very lightweight alpine image, which would allow the user to add their own volume mounts (source & destination) and run the app.

    The problem however, is the cross-device link issue.

    Under the hood in its current implementation, Switchboard just moves valid files to and from a source and destination directory using golangs os.Rename() function. The problem with doing this in a Docker context in the way described above, is that you are effectively creating two separate mount points and running os.Rename() which will fail as this calls the rename system call, which cannot rename files across devices, giving us our cross-device link error.

    One solution to avoid this is to change the Move() function and os.Rename() to create a temp file in the destination directory and copy the file contents from the source. You can see an example of this in this PR.

    This obviously has the drawback of temporarily duplicating the original file while the copy takes place before removing it after the operation has been completed, however I believe this is acceptable.

  • Switchboard launch checklist

    Switchboard launch checklist

    • [ ] Add COC readme
    • [ ] Add Contributing guidelines
    • [ ] Add more examples
    • [ ] Launch website
    • [ ] Add E2E tests for 3 os arches + have them green
    • [ ] Update video on homepage and site
Lima launches Linux virtual machines on macOS, with automatic file sharing, port forwarding, and containerd.

Lima: Linux-on-Mac ("macOS subsystem for Linux", "containerd for Mac")

Jan 8, 2023
Package fsm allows you to add finite-state machines to your Go code.

fsm Package fsm allows you to add finite-state machines to your Go code. States and Events are defined as int consts: const ( StateFoo fsm.State =

Dec 9, 2022
Control QEMU like magic!
Control QEMU like magic!

Qemantra Qemantra is a command-line tool for creating and managing QEMU Virtual Machines. QEMU is better and sometimes faster than VirtualBox , but do

Dec 26, 2022
Go library for creating state machines
Go library for creating state machines

Stateless Create state machines and lightweight state machine-based workflows directly in Go code: phoneCall := stateless.NewStateMachine(stateOffHook

Jan 6, 2023
libFFM-gp: Pure Golang implemented library for FM (factorization machines)

libFFM-gp: Pure Golang implemented library for FM (factorization machines)

Oct 10, 2022
Auto-evaluate your Golang code.
Auto-evaluate your Golang code.

Ginker Ginker is a GUI application for auto-evaluating your Golang code. It allows you to write and run Golang code on the fly and it will help you to

Jun 24, 2021
Auto Judger for BUAA-SE-OOP Course (2021 Spring)

patpat Auto Judger for BUAA-SE-OOP Course (2021 Spring) 1. 评测机使用方法 1.1. 一些准备工作 1.1.1. 下载评测机 见 GitHub 中的 Releases,下载对应版本即可。目前提供 Windows, Linux, MacOS(I

Sep 25, 2022
Auto daily report for HITSZ Students.

auto-report Auto daily report for HITSZ Students. Usage Report Once Golang go run main.go -u your-studentID -p your-password -e your-email Docker dock

Aug 25, 2022
Auto-updating F-Droid repo using GitHub Actions
Auto-updating F-Droid repo using GitHub Actions

fdroid This repository hosts an F-Droid repo for my apps. This allows you to install and update apps very easily. How to use At first, you should inst

Dec 29, 2022
An auto-scraper for EmulationStation written in Go using hashes.

An auto-scraper for EmulationStation written in Go using hashes. This currently works with NES, SNES, N64, GB, GBC, GBA, MD, SMS, 32X, GG, PCE, A2600, LNX, MAME/FBA(see below), Dreamcast(bin/gdi), PSX(bin/cue), ScummVM, SegaCD, WonderSwan, WonderSwan Color ROMs.

Oct 24, 2021
Auto-updates PaperMC Projects

Auto-updates PaperMC projects Motivation Paper has made it very difficult to auto update servers, because they discourage it. This means that you can'

Mar 15, 2022
Host yo' self from your browser, your phone, your toaster.
Host yo' self from your browser, your phone, your toaster.

A hosting service from the browser, because why not. Try it at hostyoself.com. See it in action Here's an example where I use hostyoself.com to host i

Jan 1, 2023
Simple Golang API to demonstrate file upload to fireabase storage and retrieving url of uploaded file.

go-firebase-storage -Work in progress ??️ Simple Golang API that uses Firebase as its backend to demonstrate various firebase services using Go such a

Oct 4, 2021
Works with HashiCorp HCL. Allows to append the input file with blocks and attributes from the template file

About hclmergetool Works with HashiCorp HCL. Allows to append the input file with blocks and attributes from the template file Installation Binary Rel

Feb 6, 2022
James is your butler and helps you to create, build, debug, test and run your Go projects
James is your butler and helps you to create, build, debug, test and run your Go projects

go-james James is your butler and helps you to create, build, debug, test and run your Go projects. When you often create new apps using Go, it quickl

Oct 8, 2022
Cross-platform file system notifications for Go.

File system notifications for Go fsnotify utilizes golang.org/x/sys rather than syscall from the standard library. Ensure you have the latest version

Dec 30, 2022
File system event notification library on steroids.

notify Filesystem event notification library on steroids. (under active development) Documentation godoc.org/github.com/rjeczalik/notify Installation

Jan 7, 2023
A Go parser for the /etc/passwd file

> godoc github.com/willdonnelly/passwd PACKAGE package passwd import "github.com/willdonnelly/passwd" FUNCTIONS func Parse() (map[string]Entr

Oct 20, 2022
Export the private key from a Swarm json key file

exportSwarmKey Currently it is a pain in the A** to export bee key in to metamask as they are not compatible. This programe will export the private ke

Oct 2, 2022