Trigger Context Menu Item is unreliable

I want to add a shortcut for the Finder's context menu item “New iTerm2 Tab Here".

This seems to work randomly.

  • I've tried to add an async delay either before or after the action and sometimes it helps, sometimes it doesn't.
  • When the shortcut doesn't work it usually will not work for all following triggers.
  • Sometimes I need to re-launch finder and it works again, sometimes it will start to work again on without it.
  • Sometimes it will never work again on the same window but it will on another.
  • Sometimes it will work again on the old window.

So absolutely apparently random.

How can I debug this?

Ah, also sometimes the trigger just brings up the context menu and it will stay there instead of triggering a specific item

Unfortunately there are no standard API's for this, BTT uses some dirty hacks to make this kind of work in most native apps, but in cases like this with dynamically added context menu items (coming from Finder plugins etc.) this can fail randomly. I don't think it is solvable for such context menus.

I'll have a look again, maybe for this specific case changing the internal timing behavior could help.

Ah I see thanks!
So how would I open iTerm2 with the current selection anyway without relying on context menu?
I don't really care about context menu if I can do it another way.

There is the "Open current Finder Selection With Specific App", but I think this would try to execute the file in iTerm.

Instead I'd use a little apple script:

tell application "Finder"
	set sel to selection
	if sel is {} then
		display dialog "Select a file or folder in Finder first." buttons {"OK"} default button "OK"
		return
	end if
	
	set theItem to item 1 of sel
	if (class of theItem) is folder then
		set targetPath to POSIX path of (theItem as alias)
	else
		set targetPath to POSIX path of ((container of theItem) as alias)
	end if
end tell

tell application "iTerm2"
	create window with default profile
	tell current session of current window
		write text "cd " & quoted form of targetPath
	end tell
	activate
end tell

1 Like

I did modify the timing behavior for Finder a bit, maybe the context menu action works better with 6.359

1 Like

Thanks, gave it a quick test.
Same as before, it works sometimes in unpredictable ways

I am also experiencing this with Finder. Trying to trigger the “Remove Download||Remove Downloads;” context menu item that removes local copies of files in iCloud Drive. BTT v6.380. Sometimes it just opens the context menu without triggering the item. About 25% of the time I’d say.

I guess I can try working around it by triggering ctrl + enter to bring up the context menu, delay next action, then send keystrokes “r, e, m, ”.

—————-
followupthe commands “Remove Download” and “Remove Downloads” also appear in the Finder action menu in the toolbar, the icon with three dots. I was able to add the same keyboard shortcut for both command names in system settings → keyboard shortcuts, and it works perfectly!