microsoft / PowerToys

Windows system utilities to maximize productivity
MIT License
111.41k stars 6.56k forks source link

๐Ÿ’ป Option to run ColorPickerUI (or other modules) via command line #10593

Open gaiking-uk opened 3 years ago

gaiking-uk commented 3 years ago

Hi guys,

Firstly, I would like to start by saying great work developing this great suite of tools/toys. Have been hunting for a decent cross-app colour picker, with a decent UI for years and ColorPickerUI is the best I have come across by far!

The rest of the apps are definitely useful, not suggesting that for a second - however for me personally (given the other apps/utils/scripts I put together over the years), ColorPickerUI is the main/only one I use... I would like to hook into my existing tool/script-set and wondered if there was a way to do this please (e.g. command line to invoke ColorPickerUI, that works even if PowerToys isn't running)?

Again, like I say - not trying to take away from what you guys have built as it's great!.. Just trying to consolidate/integrate parts of PowerToys into my existing config.

Cheers, Martin ๐Ÿ‘

crutkas commented 3 years ago

putting this as runner but most items are designed to assume the runner (centralized app) is ... running. It actually is what lets us run parts of code not as admin but still be able to invoke when an admin app is in focus.

martinchrzan-msft commented 3 years ago

@martin-zima You can start ColorPickerUI.exe without having PowerToys running (located here - C:\Program Files\PowerToys\modules\ColorPicker\ColorPickerUI.exe)

However you will need PT running if you want to change Color Picker settings, once you change them, PT is not necessary

gaiking-uk commented 3 years ago

Hi guys thanks both for getting back to me so quickly!

@crutkas -- am afraid am not sure what you mean as a 'runner', is this something I should do to make this work (e.g. a parameter I should set in one of the xml/json files?)

@martinchrzan-msft -- thanks for that, unfortunately it does not seem to work (at least for me).. That was actually my first idea and tried to do that before posting, however when I run <C:\Program Files\PowerToys\modules\ColorPicker\ColorPickerUI.exe> nothing happens - well, the program does run Task Manager shows a 2nd ColorPickerUI.exe process, however no UI appears... I have tried setting the Colour Picker [CP] "Activation Behaviour" to all 3 options (CP with editor, Editor only, CP only) but still can't get any UI / CP window to appear when I run the .exe (which is why I thought maybe I am missing something, like a switch / argument I need to provide, etc)

  1. Is there anything else I can do to get CP to run (in a UI/interactive mode)?
  2. If my experience does not match the expected outcome, and/or you need any further info to help replicate, etc -- please let me know as am more than happy to help!
martinchrzan-msft commented 3 years ago

@martin-zima yeah, running it will not open UI, it will just start a process, which listens to activation shortcut, only once that activation shortcut occurs, it will open UI. I thought that you want to have that, without PT running, but you want to open Color Editor immediately, right? In that case we don't really have a support for such scenario, there is no switch to open editor immediately - however it could be added easily.

gaiking-uk commented 3 years ago

Hi @martinchrzan-msft -- yes, essentially I was looking for a way to open the ColorPicker UI window (ideally in "CP with editor mode enabled) AS IF I had pressed the activation shortut, but in reality I triggered it through some other means, such as command line, etc.

... Ultimately, over the years I have put together my own mini suite of tools/scripts to help my day-to-day work. (One example is a custom tray icon with a right click menu that launces various apps). It would be great if I could intergrate ColorPickerUI into my own existing toolset, but need someway to load the ColorPicker UI without the activation shortcut.

If you can implement this, that would be great!... I will look out for this feature in hopefully the not-to-distant future (I realise this is not top of your list and you are working on other fixes/enhacements, but if it is any easy thing to add, hopefully it can be sneaked into a release sometime soon).

NB: In terms of solution requirements - I wasn't particularly looking to bypass PowerToys, like I say, I respect the great work you guys have done building this app... that said, I confess that I basically run PT just to use CP, so if there was a way to initialise CP Editor without needing needing to always have PT running, that would possibly be better for me - thanks!

martinchrzan-msft commented 3 years ago

@martin-zima Not sure how much you want to hack, but you can build it by yourself by just adding this code at the end of MainViewModel constructor (src\modules\colorPicker\ColorPickerUI\ViewModels\MainViewModel.cs)

var args = Environment.GetCommandLineArgs();
if (args.Length == 2 && args[1] == "openEditor")
{
    _appStateHandler.ShowColorPickerEditor();
}

It will open editor if you start ColorPickerUI.exe with parameter "openEditor"

Otherwise it is up to @crutkas to prioritize this feature

gaiking-uk commented 3 years ago

Awesome, thanks! ๐Ÿ‘๐Ÿผ

I will give it a try and let you know how I get on later (I mainly use VS code, but it was complaining when I tried to build the project so will install Visual Studio and see if I have more luck there).

gaiking-uk commented 3 years ago

UPDATE: Thanks for your help @martinchrzan-msft but ufortunately I am still struggling to get the code to compile on my system ( ยน further info at end of message, if desired)...

The main error I was getting was: 'AppStateHandler.ShowColorPickerEditor()' is inaccessible due to its protection level Updated file: MainViewModel.cs.txt (in case I mis-understood your instructions)

I was getting other errors too, but TBH am assuming it is down to my lack of familiarity with VS / the code, so (unless there is something quick/obvious I have done wrong), I will probably have to leave my attempts to update the file myself here, and wait for you guys to include this in an upcoming release.

Thanks again for your help your help anyway!


ยน FYI - Steps followed in trying to build the solution...

  1. I installed VS 2019
  2. Cloned the repository
  3. Installed the recommended additional VS 2019 compontents
  4. Restored nuget packages
  5. Set build confid to Release, x64
  6. Build PowerToys solution (failed)
  7. Build ColorPicker solution (failed)
CombeeMike commented 2 years ago

I'm also looking for a way to directly open color picker from cmd line without changing the activation behavior to Open editor. Ideally it would be possible to set the selected color form some cmd line argument as this would allow me to "work around" my feature requests #17335 and #17333 with some AHK script or something the like.

s-oram commented 2 years ago

Great work on the powertoys bundle. Like the other commenters here, I would also find the ability to open the color picker UI via a command line useful as I use Keypirinha to launch applications. Like the OP I will also write small scripts and tools to help with my day to day work. Keypirinha makes that kind of thing easy.

Thanks again for the great set of tools!