User Agents

Web browsers and everyday web tech, explained

Show GUI Extension Button Only for Folder Operations

· 5 min read · Extensions

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide explains how to configure a GUI extension so its button appears only when you right-click a folder, not a file or empty space. This is useful when your extension performs folder-specific actions like batch renaming, compression, or sharing. You'll need basic familiarity with your operating system's file manager extension system and access to the extension's configuration files.

What You'll Need

  • The GUI extension you want to configure (installed and working).
  • Administrator or owner access to the extension's installation directory or configuration files.
  • A text editor (like Notepad on Windows, TextEdit on macOS, or gedit on Linux).
  • Basic understanding of XML, JSON, or the specific config format your extension uses.

Step-by-Step

  1. Identify the extension's configuration file. Look for files named config.xml, extension.json, manifest.json, or similar in the extension's folder. If you're unsure, check the extension's documentation or the file manager's extension manager.
  2. Open the configuration file in your text editor. Make a backup copy first (e.g., config.xml.bak) so you can revert if needed.
  3. Locate the section that defines the context menu entries. This is usually a list of <menu>, <command>, or <action> elements. Each entry has properties like label, icon, and command.
  4. Find the condition or scope attribute. Many extensions support a target or contexts property. Look for values like file, directory, folder, or all. If you see all, change it to directory or folder (exact wording depends on the system). If no condition exists, you'll need to add one. For example, in a GNOME Nautilus extension, you'd set <attribute name="target" value="folder"/>.
  5. If the extension uses a script-based approach (like a Python or shell script), edit the script to check if the selected item is a directory. For instance, in a Nautilus Python extension, modify the get_file_items method to only return the menu item when file.is_directory() is true.
  6. Save the file and close the editor.
  7. Restart the file manager or log out and back in. This ensures the changes take effect. On Windows, you may need to restart Explorer (via Task Manager) or reboot.
  8. Test the extension by right-clicking a folder and a file. The button should appear only for folders.

Common Mistakes

  • Editing the wrong file: Some extensions have multiple config files; make sure you're editing the one that controls the context menu.
  • Using the wrong keyword: folder vs directory vs dir can vary. Check the extension's schema or examples.
  • Not restarting the file manager: Changes often don't apply until the file manager is fully restarted.
  • Syntax errors: A missing quote or bracket can break the entire extension. Validate your JSON or XML before saving.
  • Forgetting to backup: If you make a mistake, you might need to reinstall the extension if you didn't backup.

Tips

  • Use the extension's documentation: Most popular extensions have a wiki or README that explains the config format.
  • Test with a simple change first: Change one thing at a time to isolate issues.
  • Look for community examples: Search online for "[extension name] show only for folders" to see how others did it.
  • If the extension has a GUI settings panel, check if it offers a "contexts" or "target" option—that's often easier than editing files manually.
  • When editing scripts, use print() statements or logging to debug why the button isn't appearing.

Troubleshooting

If the button still appears for files or not at all:

  • Check the file manager's logs: On Linux, run the file manager from the terminal to see error messages. On Windows, check the Event Viewer for extension errors.
  • Verify the condition syntax: Look at a working example from the extension's source or docs. Sometimes the condition needs to be a regex or a list.
  • Clear the file manager's cache: Some file managers cache extension data. Restarting may not clear it; try clearing the cache folder (e.g., ~/.cache/nautilus on Linux).
  • Reinstall the extension: If all else fails, uninstall and reinstall, then apply your changes carefully.
  • Check for conflicting extensions: Another extension might be overriding the menu. Temporarily disable others to test.

Frequently Asked Questions

Can I do this without editing files?

Some extensions provide a GUI settings dialog where you can select target types (files, folders, both). Check the extension's preferences first. If not, manual editing is required.

What if my extension uses a different config format?

The principle is the same: find the menu definition and add a condition that filters by item type. Refer to the extension's specific format (e.g., YAML, INI) and look for a "target" or "scope" key.

Will this work on all file managers?

No, the exact method varies. This guide covers common systems like Nautilus (GNOME), Dolphin (KDE), and Windows Explorer. Each has its own extension API and config style.

Why does the button still show for files after I changed the setting?

You might have edited the wrong config file, or the file manager hasn't reloaded. Double-check the file path and restart the file manager completely. Also, ensure you changed the correct attribute—some extensions have separate conditions for files and folders.

Can I show the button for both folders and drives?

Usually yes, if the extension supports multiple targets. You may be able to specify a list like target="folder,drive" or add multiple conditions. Check the extension's documentation.

Is there a way to test without restarting the whole system?

On Linux, you can often restart just the file manager with nautilus -q or killall dolphin. On Windows, right-click the taskbar and select "Task Manager", then restart Windows Explorer. This is faster than a full reboot.