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.

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

Illustration that symbolizes the importance of governance in ESG

Business | 15/11/2024

Governance in ESG: Why Strong Leadership is Key to Sustainability?

Łukasz Kopaczewski

While all three pillars—environmental, social, and governance—are essential, governance often plays the most foundational role. Governance, which includes ethical leadership, transparency, and accountability, ensures that ESG efforts are not just statements on paper but integrated into a company’s everyday decisions. Notably, a recent study found that 39% of companies feel they perform adequately on governance, indicating significant room for improvement​.

Read more
Illustration to the article on Making Data-Driven Decision and AI

Business | 08/11/2024

Making Data-Driven Decisions: How Artificial Intelligence Can Help You Avoid Common Pitfalls

Agata Pater

Relying solely on intuition in business can often mean missing out on big opportunities. Consider Netflix as a prime example. By analyzing over 30 million daily 'plays' and countless subscriber ratings and searches, Netflix pinpointed exactly what viewers wanted, leading to the creation of hit series like House of Cards. This data-driven approach didn’t just increase viewer engagement; it revolutionized the entertainment industry’s approach to content creation. Embracing Data-Driven Decision Making can similarly empower companies to craft more precise strategies, avoid common pitfalls, and make choices that resonate with actual market demand.

Read more
Illustration to the article about importance of ESG factors in construction sector, and how AI can help in reporting sustainability efforts.

Business | 31/10/2024

The Growing Importance of ESG in Construction Industry

Bernhard Huber

The construction industry is a critical driver of economic growth, responsible for creating the infrastructure that supports communities and industries worldwide. However, this sector also faces substantial challenges related to environmental degradation, social equity, and governance issues. Increasing global awareness of climate change, heightened investor scrutiny, and evolving regulatory demands have led to a fundamental shift in how construction companies approach their operations.

Read more