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 to the article about improving sales in ecommerce industry

Development | 13/09/2024

How to Improve Sales in E-Commerce Business? IT solutions for the eCommerce industry

Łukasz Kopaczewski

In the world of eCommerce, where competition is constantly increasing, online store owners must reach for innovative tools to increase sales and build customer loyalty. The key to success is the right IT solutions that automate sales processes, personalize the shopping experience and integrate with various systems. In this article, we outline the most effective ways to increase the efficiency of your online store to stay ahead of the competition.

Read more
preview illustration with icons representing education and technology

Innovations | 11/09/2024

Use of Technology in Education: How Is It Bridging the Educational Gap?

Agata Pater

The barriers that once defined educational access—geographical location, economic status, and availability of resources—are gradually being dismantled. As we continue to innovate and implement new technologies, the gaps that have traditionally separated students around the world are closing, bringing us closer to an era of truly equitable education.

Read more
Illustration for the article about AI and sustainable energy

Innovations | 05/09/2024

Revolutionizing the Energy Sector: The Role of AI in Clean and Renewable Energy Transition

Bernhard Huber

As the global community grapples with the challenges of climate change, the shift towards renewable energy sources has never been more critical. The transition to clean energy is not only essential for reducing carbon emissions but also for ensuring a responsible future for generations to come. At the forefront of this revolution is artificial intelligence (AI), a powerful tool that is transforming how we produce, distribute, and consume energy. AI technologies are increasingly being integrated into the energy system, optimizing everything from energy generation to energy storage, and paving the way for a more efficient and resilient energy infrastructure.

Read more