Image for the Tutorial on The File Watchers Tool

The File Watchers Tool in PHPStorm: Tutorial

30/06/2023

What is File Watchers and How Can it Help You?

Once upon a time, in the vast universe of programming, repetitive tasks were a common source of headaches. Then, along came the "File Watchers" tool, built into the PHPStorm IDE. It swept onto the scene, promising a solution for those tiresome tasks that seemed to eat up so much of a developer's day.

Have you also found yourself looking for a tool that could automate some tasks in your programming routine? Something that would take over mundane actions, freeing up your time for more complex coding tasks? If yes, then you're in good company!

The Advantages of using File Watchers

You might be wondering, "But what about built-in observers in many modern frameworks and tools?" True, they're useful, but "File Watchers" has its own charm. While developing a module for PrestaShop, I found myself yearning for a solution that would allow me to automatically create a compressed module, ready for verification and installation. In particular, I wanted this process to be triggered each time I saved the file I was working on. This desire led me down the rabbit hole, and I discovered the "File Watchers" tool available by default in the PHPStorm IDE.

What sets "File Watchers" apart is its high degree of configurability. It offers the opportunity to connect various programs to be set in motion each time a file is saved. It's like having a digital genie, waiting to fulfil your command at the click of a save button.

To summon this genie, you only need to follow the magical pathway: “Preferences -> Tools -> File Watchers”.

Image showing where to find file watchers category in preferences on macos

How to use File Watchers: Tutorial

When the window pops up, you have the power to add a new watcher, adjust existing ones, or banish those that no longer serve your needs. To initiate a new watcher, all you need to do is click on the little "+" icon. From there, you can select from a suite of pre-existing templates (like those tailored for the SASS preprocessor), or if you're feeling adventurous, you can craft a fresh setting. For the purposes of this post, and perhaps your own explorations, choosing "<custom>" could be just the right amount of spice you need to add to your coding recipe.

Screenshot illustrating how new file watcher window looks like

The "File Watchers" tool boasts a plethora of options. PHPStorm allows you to select the file type that triggers an action upon modification. The "scope" option provides a nifty advantage, as it can be restricted to only VCS-committed files, which I believe makes the workflow a lot smoother. Other key options include "Program" and "Arguments", where you can choose the appropriate executable file and its parameters, respectively.

Additional settings let you decide where the tool's output and logs should be written, set environment variables, and specify the folder where the watcher will operate. Advanced options, such as tracking files after automatic save or tracking external changes, are available at your disposal, along with the possibility to control what appears in the terminal and filter the output.

To meet my specific needs, I created a Bash file. Imagine the scenario in PrestaShop module development: a Bash file is created that, upon triggering the rsync and zip commands, copies all required module files into a separate folder, then creates a compressed file ready for deployment and verification. It's like having an automated assembly line, taking care of the monotonous production while the developer focuses on the design and quality control.

Try it Yourself

So, next time when the tedium of repetition starts to creep into your coding routine, let "File Watchers" be your escape hatch. Think of it as a magical tool within PHPStorm IDE, ready to take away the monotony of your programming journey, helping you reach new pinnacles of creativity and productivity. In its wide range of capabilities, "File Watchers" not only helps streamline complex projects but also guides you efficiently through the intricacies of the coding process, serving as a reliable guide.

The File Watchers Tool in PHPStorm

The File Watchers Tool

PHPStorm

What is File Watchers

Advantages of using File Watchers

How to use File Watchers

Pa
The photo of the article's author - back-end developer at Primotly. The picture shows a professional young man with short hair and glasses looks directly at the camera.
Paweł Turek
Back-end Developer

Latest articles

Abstract visual of staff augmentation and IT body leasing workflow represented with icons for collaboration, vision, and goals on a light blue background.

Business | 31/01/2025

Can Staff Augmentation Service Be Affordable?

Agata Pater

The evolution of the global talent market and modern recruitment processes has made it possible to access top tech talent without breaking the bank. Staff augmentation services can be remarkably cost-effective when compared to traditional hiring methods, especially when considering the hidden costs of maintaining an in-house team.

Read more
Illustrative preview of DeepSeek AI logo featuring a stylized whale icon on a turquoise background with abstract design elements.

Innovations | 29/01/2025

DeepSeek AI: The Chinese AI App That’s Challenging OpenAI

Bernhard Huber

At its core, DeepSeek differentiates itself through its commitment to open-source development, making its technology more accessible to developers and researchers worldwide, much like OpenAI's approach. This approach stands in contrast to the more closed systems of some competitors, creating a collaborative environment for AI advancement, similar to the open source movement. 

Read more
Illustrative design featuring arrows, charts, and a collaborative icon on a blue background, symbolizing growth and success in staff augmentation solutions.

Business | 23/01/2025

How to Find the Right Staff Augmentation Partner?

Agata Pater

According to recent industry research, approximately 78% of global companies utilize staff augmentation services to accelerate their development projects and meet tight deadlines. Staff augmentation offers a strategic advantage by providing access to a managed service that can adapt to your changing needs. This growing trend reflects the challenging reality many businesses face: finding and retaining in-house tech talent has become increasingly competitive and costly.

Read more