In autohotkey, can you daisy chain together hotstrings from different scripts?
Note that I'm using autohotkey v2, not v1.
I want to run two different autohotkey scripts. I want to trigger a hotstring in the first script, the output of which ends up being part of the hotstring trigger for the second script. Is this possible?
Here's a simplified version of my intended workflow.
Script 1:
#Hotstring EndChars \
#Hotstring o
#Hotstring ?
::iv::ǐ
::av::ǎ
Script 2:
#Hotstring EndChars \
#Hotstring o
#Hotstring ?
::nǐ::你
::hǎo::好
So the idea is that I can type niv\ and the first script will convert it to nǐ - then I can immediately type \ and the second script will convert it to 你. So I type niv\\ and my text goes from niv to nǐ to 你. I can then type hav\o\ and have my text go: h, ha, hav, hǎ, hǎo, 好. So I can do niv\ hav\o and get nǐ hǎo, or I can do niv\\ hav\o\ and get 你 好. Both writing systems in a reasonably simple format.
There are reasons I want to set it up like this. The first script has dozens of functions beyond writing in pinyin/chinese, and I share it with another person - so I don't want to add potentially hundreds of random Chinese hotstrings to it, just the special pinyin characters. That's why I'm using two scripts.
But I also realize I could just make "niv" and "havo" their own hotstrings which go directly to 你 and 好 without the intermediate nǐ and hǎo. I don't want to do this mostly because I think the system I have in mind is prettier - type it correctly in pinyin first, then have it correctly convert to Chinese.
All of that aside: I've gathered that this is probably possible using some combination of SendLevel and #InputLevel - but I've tried a bunch of different combinations and ideas with it, and haven't successfully had one script trigger another yet. Even in simplified toy scripts, which is a little discouraging. Ideally I'd be able to do this with as few changes to the main script I share with another person as possible - the script that handles the Chinese can be as complicated as it needs to be though. Anyone know how to make this work?
#Hotstring o
#Hotstring ?
#Hotstring EndChars \
::nǐ::你
This works exactly how I want it to - which is definitely good. But I kind of hate this solution because 100% of the changes happen on the side of the original script - the giant script I share with another person.
If nobody else has a different way to do this that keeps most (not all) changes to the second script, I can make do and manage with this - but before I go ahead and make a bunch of changes, does anyone know a better way?
I'll be honest that I also don't understand the SendInput or #InputLevel stuff at all. I basically lucked into this combination after trying everything else. The stuff with B0 and {backspace} is because having it auto-remove the iv before sending ǐ made the nǐ hotstring in script 2 not work for whatever reason. That's the main reason I want to find an alternate solution - in total I'd have to alter 48 different hotstrings to do this in the main script for full functionality. Not the end of the world, but it's adding complexity to an otherwise simple part of the script for the sake of a secondary script that only I use.
One last reply to say that, unless someone else replies with an amazing solution, this is what I've decided to go with:
I'm keeping the pinyin characters in the main script (They fit thematically with the rest of the script), but I'm moving both the pinyin and Chinese to its own separate script, and giving it its own EndChar to prevent conflicts. I found the following single-script setup that works (Because, for some reason, the setup in my previous comment doesn't work if you shove it into one script):
To me this is less abhorrent than adding complexity to the main script, and it only comes at the cost of having to learn a new EndChar. I would still love a solution that let me do what I originally wanted to do without making major changes to the first script. Cheers.
It requires no changes at all to the original script, but lets me keep the same EndChar, with no chance of clashing. It gives me some extra complexity in this script with the B0 flag but that doesn't bother me - and I don't have to mess with SendLevel or #InputLevel at all, which is nice because I had no idea what they were doing anyways. And it gives me the exact behavior I was after originally: I type niv\ hav\o for nǐ hǎo, or niv\\hav\o\ for 你好.