Posts: 1,208
Threads: 279
Joined: Jul 2022
I want to implement a context menu trigger that appears in File Explorer. Specifically: when I select two folders and right-click, a specific menu item should be displayed. Clicking this menu item will pass the paths of the two folders as parameters to a specified LA script file.
(Note: this menu item should not be shown when only one folder is selected.)
Is there a simple and reliable way to achieve this?
Thanks in advance for any suggestions and help.
Posts: 12,256
Threads: 144
Joined: Dec 2002
In file `Window triggers`
Triggers.Window[TWEvent.Visible, "", "#32768", "explorer.exe"] = t => {
if (wnd.findAll("", "#32768", "explorer.exe").Length > 1) return; //submenu
var m = new popupMenu("d914e490-6ce6-4319-b979-cf0de0322f43");
var wExplorer = wnd.active;
if (ExplorerFolder.Of(wExplorer) is { } e && e.GetSelectedItems() is { Length: 2 } sel && filesystem.exists(sel[0]).Directory && filesystem.exists(sel[1]).Directory) {
m["2 folders"] = o => {
keys.send("Esc"); //close the Explorer's menu
script.run("2 folders", sel[0], sel[1]);
};
}
if (!m.Items.Any()) return;
var wMenu = t.Window;
m.Show(PMFlags.AlignRight, excludeRect: wMenu.Rect, owner: wMenu);
};
Posts: 1,208
Threads: 279
Joined: Jul 2022
01-17-2026, 10:10 PM
(This post was last modified: 01-17-2026, 11:43 PM by Davider.)
Thanks for your help!
This approach is truly elegant and doesn’t require modifying the shell menu.
How can the following code be made compatible with selecting the folders on the desktop?
// class "Window triggers.cs"
using Au.Triggers;
partial class Program
{
[Triggers]
void WindowTriggers()
{
Triggers.Options.ThreadNew();
if (true)
{
Triggers.Window[TWEvent.Visible, "", "#32768", "explorer.exe"] = t =>
{
if (wnd.findAll("", "#32768", "explorer.exe").Length > 1) return; //submenu
var m = new popupMenu("d914e490-6ce6-4319-b979-cf0de0322f43");
var wExplorer = wnd.active;
if (ExplorerFolder.Of(wExplorer) is { } e && e.GetSelectedItems() is { Length: 2 } sel && filesystem.exists(sel[0]).Directory && filesystem.exists(sel[1]).Directory)
{
m["2 folders"] = o =>
{
keys.send("Esc"); //close the Explorer's menu
script.run("2 folders", sel[0], sel[1]);
};
}
if (!m.Items.Any()) return;
var wMenu = t.Window;
m.Show(PMFlags.AlignRight, excludeRect: wMenu.Rect, owner: wMenu);
};
}
}
}
How can the menu be displayed as close as possible to the mouse cursor (next to the original right-click menu)?
In many cases, the new menu appears on the left side of the original right-click menu, far away from the mouse cursor and requiring extra mouse movement, as shown in the image below.
https://i.ibb.co/TxDVS3G6/pic.png
Posts: 12,256
Threads: 144
Joined: Dec 2002
From desktop can't use `ExplorerFolder`. Alternative - let the script get paths via the clipboard.
---
I added the flag because in most cases the shell context menu is on the right from the mouse. If need such fast access, then maybe a hotkey would be better.