Need a New Watch Case? Top Picks and Where to Buy Them!

by Rod Nichol

Okay, so I wanted to keep a closer eye on some files on my computer, specifically a folder where I dump all my downloads. You know how it is, stuff piles up in there, and sometimes I accidentally delete things I need. So I decided to set up a little “watch” on that folder. This is my journey of how I did it.

Need a New Watch Case? Top Picks and Where to Buy Them!

Getting Started

First, I needed to figure out how to actually watch a folder. I did some quick searching and found this thing called “watchman”. It sounded promising, something about “watching files,” yeah, that’s exactly what I needed.

I went ahead and installed it. I’m on a Mac, so I used Homebrew. It was pretty straightforward, just typed in a command in the terminal, and boom, it was installed. If you are not using Mac, maybe you can try to find some tutorials that fit your operating system.

Setting Up the Watch

Next, I had to tell Watchman which folder to watch. I navigated to my downloads folder in the terminal (lots of `cd` commands, haha). Then, I used the `watchman watch` command, followed by a dot ( `.` ) which I think means “current folder”. Seemed simple enough!

Figuring Out What to Do

Now, just watching the folder wasn’t enough. I needed Watchman to do something when a file changed. I wanted it to, I don’t know, maybe just tell me what happened? Like, “Hey, a file was added!” or “Whoa, you deleted something!”.

I stumbled upon this `watchman trigger` command. It sounded like what I was looking for – a way to set up a “trigger” that would run a command whenever something changed in the watched folder. So it’s like setting up a trap, once something happens, the trap will be triggered.

Need a New Watch Case? Top Picks and Where to Buy Them!

Crafting the Trigger

This part got a little tricky. I had to create a “trigger” with a specific name. Let’s call this trigger “my-download-trigger”. And then tell it what to do. I decided to start simple, just have it print the name of the changed file to the console. I remember I needed to use a weird `–` thingy to separate the trigger options from the command I wanted to run. I’m not entirely sure why, but it worked, so I didn’t question it too much.

The command I finally used looked something like this:

watchman trigger . my-download-trigger — echo

It’s important to include that dot ( `.` ), which is a placeholder that will be replaced with the actual changed filename.

Testing It Out

I saved my trigger, crossed my fingers, and then… I downloaded a picture. And there it was! In the terminal, Watchman printed the name of the picture I just downloaded! Success!

Need a New Watch Case? Top Picks and Where to Buy Them!

I tried deleting a file, and yep, it printed that too. It was working!

Then I added an new picture to test whether the trigger will print the new name of the file, and it did print the name of the picture correctly!

What’s Next?

For now, this simple setup is enough for me. It gives me a basic idea of what’s happening in my downloads folder. But I can see how this could be really powerful. Maybe I’ll set it up to automatically organize files, or even run a script to back them up. The possibilities seem pretty endless!

You may also like

Leave a Comment