20241002-thoughts_on_open_source_software.txt

I'm probably more ancient Chinese than I am Stallman. Pretty much all
my scripts are tailored to my workflow (not yours) and I therefore
don't share my code. I think growing up as the Internet did made me
wary of sharing information. I have criticized others (Greeks) in the
past for being dreamers and not doers (as opposed to Romans). What is
the point of knowledge and advanced technology if you don't share it?
I'm probably being a hypocrite, but again, most of my scripts improve
MY workflow, which may be very different than others. They are mostly
modular and are somewhat dependent on each other. There's also the
possibility that it's somewhat motivated out of pettiness: if I had to
do all the work, why should you get all the reward? Perhaps it's just
that I don't feel like my scripts are very important in the long run:
anyone could have written a bash script. Whatever my reasons are for
my reluctance for sharing code, I certainly don't vilify those who do
share code nor those who don't.

I recently discovered a way to make my workflow as an admin in Win
much easier. Back in 2020 I switched to Dvorak, and while it has been
much easier. Back in 2020 I switched to Dvorak, and while it has been
a real help with my hands and typing, it has also been a real
annoyance as a sysadmin who works on dozens of PCs, none of which will
retain my keyboard preferences for very long. My "solution" to this
was to either just use QWERTY, which I have to do to log in anyway, or
go through every hoop MS set up in Win10/11 just to add Dvorak. It was
tedious and I KNEW there was a script I could make to do that for me.

So I found a pwsh script that would enable me to do that. The problem?
The domain security policy prohibits running unsigned pwsh scripts.

Not pwsh commands themselves, but just pwsh script files. I was
peeved. But I also had been using batch scripts unchecked, so I
figured I could do the same with this keyboard issue. I mean all you
had to do was prepend the pwsh commands with "p0wershe11 ". But it
wasn't that simple.

It took a long time to get it right. I had seen one StockAverflow
question about it with a pwsh script answer--both helpful and
unhelpful at the same time. I needed a one-liner because running pwsh
commands via batch is not something that retains variable data, and
the geniuses behind pwsh decided that SetValue -value
$(GetValue)[i]=newvalue is invalid and requires 3 commands to read
current lang info and add Dvorak. I tried pipes, redirects, newlines
etc. to no avail.

I FINALLY was able to break through by using double-quotes to enclose
the pwsh commands. Unlike other options that directly accessed items
in an array, I opted to use Add(). It did what I needed it to do and I
was ecstatic. But I knew that I could make it a bit more
robust/expandable with variables defining the Dvorak and QWERTY
layouts. I tried but, as I feared, putting batch vars inside pwsh code
wasn't exactly working. I just reverted back to using the raw strings
and did some tweaking.

I currently have a solution that adds Dvorak, nixes QWERTY, pauses
until you press any key while the batch window is active, and adds
QWERTY and removes Dvorak. Outside of having to open a drive folder
and batch file, it's pretty simple, fast, and doesn't cause an
inconvenience for the QWERTY user.

But yes, there is no good solution online for my particular problem
thanks to group policy, but I made a solution after several hours
diving into documentation and online posts.

But below is the code in case anyone reading needs it. It obviously
has remnants of previous implementation(s), but it works:

'''
REM dvorak.bat
@echo off
echo Switching to en-DV
powershell "$l = Get-WinUserLanguageList;
$l[0].InputMethodTips.Add('0409:00010409');$l[0].InputMethodTips.Remove('0409:00000409');Set-WinUserLanguageList -LanguageList $l -force;"
echo KEEP THIS WINDOW OPEN. Press any key when you're done using
Dvorak
PAUSE
echo Ready to go back to QWERTY?
PAUSE
:REMOVE_DV
powershell "$l = Get-WinUserLanguageList;
$l[0].InputMethodTips.Remove('0409:00010409');Set-WinUserLanguageList
-LanguageList $l -force"
:THE_END
'''