Cautomaton author here, summoned from the grave and beyond!
I have re-read this thread a few times, and I am still a bit confused as to what MourningStar wants to achieve exactly. I think I understand, but for the sake of clarity, I will restate what I think the question is so that I can then give a proper answer, if only to avoid confusion later.MourningStar wants to use Windows Explorer, select music files, and with a single key press choose a particular action in the context menu (also known as popup menu) that would appear if one right-clicked these files.
If I am wrong on any of this, please clarify this clearly.Tackling the issue DIY-Coding-Snack-Style
This problem consists roughly out of two or even three parts.
1) Something needs to detect the key press, likely a global hotkey. There are tools for this. This is the starting point for where the 'logic' begins.
2) Something needs to figure out which Explorer window is on top and determine the files selected therein.
3) Something needs to simulate selecting the correct item in the sub menu.
My little tool Cautomaton
only tries to tackle the third option. It is a tool meant to automate a very specific purpose, and as such does not have the functionality of points 1) and 2).
Items 1) and 2) might be the same program, or they could be separated into two. I am sure though that others can in fact point you towards a relevant tool for this. If no easy, existing tools exist for this, and knowing how talented some people in these forums are, someone could likely script these parts together using something like AutoHotkey. But I think one of the many tools released on DoCo might already supply this functionality. (mouser, I am looking at you and all your automation robots here!
) But I might be mistaken given how little time I have spent here as of late.
Since Cautomaton can at least cover part of the problem, I'm going to dive into it to show what it may do for you on this occasion.Cautomaton basics
Windows file associations and the context menus that result from them are frankly a messy monstrosity built up throughout ~25 years of Windows development. For novice and expert users alike, it is very difficult to understand why some menu items appear when they do, and why they appear in the positions they do. Even today, I am frequently stymied by the behaviours I observe, and there this is why I have built an analysis function into Cautomaton that hopefully makes finding the correct magic incantation as painless as possible.
Because I had to dig up my Windows 7 VM (30 minutes of forced updates...) and then put Cautomaton on it, I figured all the time might as well be worth it and I went and created a couple of screenshots for educational purposes. These are the files I'll be talking about.
Note that I collected a couple of different file formats: one mp3, one wma, one flac. To Windows, these are all different, and especially once you start dealing with selections of multiple files, you can potentially run into problems where Windows decides to hide entries because it believes a menu item does not apply. You'll note that my FLAC song is not supported by Windows / WMP. I'll primarily focus on the mp3 file in this post, but this serves mainly as a reminder that multiple selections can be very
You'll see that I put both the 32-bit and 64-bit version in there. Why? Because both versions will very likely show you rather different menus! If your machine and Windows are anywhere close to recent, the 64-bit version should suffice for all your needs... but some programs may simply not show up on one or the other popup menu. Myriads of reasons aside: it is important to be aware of which version you are using if you end up having problems not seeing menu items you should be seeing. My examples will use the 32-bit version of Cautomaton, although you should probably use the 64-bit version because 32-bit is positively ancient. (I made my screenshots before I typed all this, and never gave it much thought. Do as I say, not as I do....
From here on, everything happens in the command window (cmd.exe).
Here I run Cautomaton with the following switches:
- /P - this option tells Cautomaton to show a context (popup) menu for human interaction
- /A - this option tells Cautomaton to run in analysis mode
- /N - this option tells Cautomaton to not actually execute the chosen action (it is late for me right now and I don't want to risk waking up the neighbors!)
- my mp3 music file
You can see that I am about to click the 'Add to Windows Media Player' list, because I assume that is the one the OP wants.
Analyzing an action will output three pieces of information: information related to the 'verb', information related to the 'trail', and finally the recommended means of reproducing the given action.
Verb related information:
Verb (Unicode): Enqueue
Help text (Unicode): Add to Windows Media Player list
Verbs are the ideal means of interaction as this is a language-neutral concept that is native to Windows itself. They practically exist for the purpose of automation and if present, is always what you will be recommended to use. Verbs are supposed to be the same regardless of you using an English, Dutch, Chinese or Japanese system.
Unfortunately enough, far too many menu options do not offer verbs due to oversights, plain laziness or even because they want to prevent automation. Which is where trails come in.
Caption: &Add to Windows Media Player list
Neg. Position: -20
Trails are a Cautomaton concept based on the idea of having a breadcrumb trail to retrace ones steps. Unfortunately, context menus themselves are not meant for automated interaction, and are very much subject to change depending on the selected files. Some entries change name depending on the file selected. Others can only be pinned down because they like to snuggle in as the fifth item from the bottom. Yet others may be very stubborn about an internal ID.... anyhow, you probably get my point: this is macgyver-esque 'it works for me' and 'do not wake up sleeping bears' territory.
Recommended Cautomaton parameters: /v Enqueue
And finally the recommendation. Thank the gods: it is a verb!
In this case, if we want to reproduce right-clicking the mp3 and choosing this action, the program suggests running:cautomaton32.exe /v Enqueue "01 - Over Distant Shores.mp3"
And while screenshots can't quite do the music justice
, I can confirm this works perfectly on my end. (After waking up the neighbors, goddangit!)
Multiple files?cautomaton32.exe /v Enqueue "01 - Over Distant Shores.mp3" "02 - Chrono Trigger.wma"
Also works! (I could make a screenshot of WMP having those two in a playlist... but you get the gist of it by now I think.)
Adding the FLAC file... Unfortunately, WMP rejects that one with its entire being: it does not show up. However, the other two do, which suggests that on this occasion at least the menu item didn't disappear outright just because an incompatible file was selected.So what now?
This depends entirely on the program(s) used to cover points 1) and 2). I can't help you with that, I am afraid...
... but...!Tackling the issue Common-Sense-style
This is where I tell you not to use my program. Cautomaton is a tool that exists to unlock tricky doors that otherwise stay locked, but it isn't always the right tool for the job. And this is exactly one of those situations where the K.I.S.S. principle (Keep It Simple, Stupid!) rules supreme.
Let's be honest: all you want is to hit a key and have something happen. This is not so much about dependable automation that should happen behind the scenes as part of a bigger whole. If something doesn't work, you'll be right there to figure out WTF is going on.
Looking back at the trail information above, you can see that the caption is '&Add to Windows Media Player list'
. The ampersand is used to denote a hotkey. Unfortunately, around the Windows XP era the default behaviour became to hide all those 'confusing keyboard shortcuts' by default to make things look nice and only have them show up when you press alt... but with popup menus that also close quite easily when keys are being pressed most people aren't even aware these shortcuts exist anymore!
Combined with the tip someone else already gave up above in regards to popping up the context menu using the Context key on the right side of your keyboard, we have minimized the solution to two actions key presses: CONTEXT, A
And with that in mind, we suddenly have another way we can automate your problem: by finding an application that can assign a single keypress to execute two keypresses
. Such basic macro tools are a dime-a-dozen, and although I do not personally use any, someone here should be able to give you a recommendation for a good one.
Note that this solution is by far preferable: Windows Explorer will do all the heavy-lifting exactly as it is supposed to do and far less complexity is involved.
Just because I wrote a tool that can solve a part of the problem does not mean the tool is the right tool to solve the problem.