H
HASS.Agent•11mo ago
Evostance

Triggering Powershell not working

Following on from https://discord.com/channels/932957721622360074/1208148867799982112 Currently running the forked version, but unable to get Powershell to trigger the command Switch-Desktop -Desktop "Desktop 2"
No description
Solution:
Ah, escaping the quotes fixed it for the command too
Jump to solution
37 Replies
Evostance
EvostanceOP•11mo ago
Interestingly, I tried the PowershellSensor and tested the script there, got this error
DrR0x
DrR0x•11mo ago
@Amadeo This is obvsly something to do with quotes in ha and stuff @Evostance what it's saying is that there is no quotes around desktop 2 in the Hass agent call and so the command gets confused as to what 2 means. It sees: - switch desktop - desktop is Desktop - 2 is an extra argument the command is not expecting
Amadeo
Amadeo•11mo ago
Wait Didn't we already talk about it somewhere
Amadeo
Amadeo•11mo ago
GitHub
Fix: Powershell command argument binding by amadeo-alex · Pull Requ...
This PR fixes how action arguments are passed on to the PowershellCommand. Previously whole action string was passed as a one argument, this prevented parameter binding - after the changes the acti...
Amadeo
Amadeo•11mo ago
Although the "Desktop 2" should be in quotes either way - like I just written I think
Evostance
EvostanceOP•11mo ago
Yep, so it is in quotes on the sensor. Hence why wondering if the command has the same problem
No description
Evostance
EvostanceOP•11mo ago
Switch-Desktop -Desktop \"Desktop 2\" seems to work on the sensor
Solution
Evostance
Evostance•11mo ago
Ah, escaping the quotes fixed it for the command too
DrR0x
DrR0x•11mo ago
So fixed then?
Evostance
EvostanceOP•11mo ago
No description
Evostance
EvostanceOP•11mo ago
Yeah, would be ideal though if you didnt need to escape the quotes in the actual script within Hass agent, but "fixed"
DrR0x
DrR0x•11mo ago
nvm, sry this is in agent. that's weird. I assume its how we parse it right @Amadeo ?
Evostance
EvostanceOP•11mo ago
no no, escaping those characters is needed in hass agent too oh ha = hass agent, not home assistant lmao
DrR0x
DrR0x•11mo ago
nah it means home assistant i just miss typed 🤣
Evostance
EvostanceOP•11mo ago
oh 🤣
Amadeo
Amadeo•11mo ago
With commands its just passed to powershell.exe but I'll see if there is smth on our side that forces the " to be escaped hm, looks about right
$@"& {{{command}}}"
$@"& {{{command}}}"
damnn, I'll need to install that Switch-Desktop thingy again so, this works:
Switch-Desktop -Desktop "Test123"
Switch-Desktop -Desktop "Test123"
but this doesn't
Switch-Desktop -Desktop "Test 123"
Switch-Desktop -Desktop "Test 123"
looks like it's not really fixable in code (easily, I'll fiddle with encoded parameters) and the only two options are:
Switch-Desktop -Desktop 'Test 123'
Switch-Desktop -Desktop 'Test 123'
or
Switch-Desktop -Desktop \"Test 123\"
Switch-Desktop -Desktop \"Test 123\"
ok, I got it working with the encoding option however with this only following work (excaping is not required and it breaks the pasring of parameters):
Switch-Desktop -Desktop "Test 123"
Switch-Desktop -Desktop "Test 123"
Switch-Desktop -Desktop 'Test 123'
Switch-Desktop -Desktop 'Test 123'
@Evostance what's your opinion 😄
DrR0x
DrR0x•11mo ago
Wait so right now single quotes work fine or are there issues with that?
Amadeo
Amadeo•11mo ago
they do at least on the fix/test branch I created
DrR0x
DrR0x•11mo ago
Ah okay so either way you have to change it? Yep just re read comment makes sense now Look I reckon double quotes as long as it doesn't break anything else but that's just because most people use double quotes for paths and stuff in CMD/powershell But I also get the argument for single quotes because this is being used in yaml
Amadeo
Amadeo•11mo ago
With the change both will work but I'm thinking that some ppl might have figured out the escape optiom with current build - which will break for them after the change We might just mark it ad a breaking change, for me "" and '' make more sense than '' and ""
DrR0x
DrR0x•10mo ago
Ah okay, look I would count that as a very minor breaking change so no need to worry about version stuff 😂
Evostance
EvostanceOP•10mo ago
Did something change in the latest beta :/ Seems publishing no longer triggers the powershell stuff
Amadeo
Amadeo•10mo ago
yes and no Edit: not in case of this :D goddamnit the powershell stuff is like a flip switch you fix one thing and nother is borked wait ^ this works for me what is not working for you the encoding change was not included in the 2.1.0-beta1 so it's as been before details please 😄
Evostance
EvostanceOP•10mo ago
hmmm So actually, MQTT didnt work but the button did lol So, might not be anything to do with encoding Also, i changed it to Switch-Desktop -Desktop 'Desktop 2' still works fine
Amadeo
Amadeo•6mo ago
@DrR0x @koshi Sorry for pings only but quite busy with work atm 😄
DrR0x
DrR0x•6mo ago
All goodz thx for that, knew we did this at some point 😂
koshi
koshi•6mo ago
same here 😉 quoting hell... C:\"Program Files (x86)"\Steam\steam.exe
DrR0x
DrR0x•6mo ago
Does that work?
koshi
koshi•6mo ago
no - because discord is eating up half the escape codes itself
DrR0x
DrR0x•6mo ago
Use
`
`
either side
koshi
koshi•6mo ago
No description
koshi
koshi•6mo ago
this works
DrR0x
DrR0x•6mo ago
Hmm, have you tried on mqtt exp? It shouldn't need to be this long
koshi
koshi•6mo ago
I just added the third escape at the beginning because I was afraid that it would mix it up with the directory slash
DrR0x
DrR0x•6mo ago
Yeah but still, it's been implemented to not require escaping assuming you have a newer beta
koshi
koshi•6mo ago
thats good to know - I will probably fiddle around with it more once I have more complicated stuff but for the moment it works, so its good enough 😉
DrR0x
DrR0x•6mo ago
If it ain't broke don't fix it
Want results from more Discord servers?
Add your server