Score:1

Autokey Creating a Global Variable

ae flag

In autokey, how can I create a global string variable that can be used by all scripts?

You see, sometimes I need to change this string that I use in many scripts. When I do this, it is a lot of work because I have to modify that string in numerous autokey scripts. If I could create a global variable, I would be able to modify this string in one place, and it would automatically effect all scripts that use it. I need this!

I found this in the documentation:

set_global_value(self, key, value)
    source code 

Store a global value

Usage: store.set_global_value(key, value)

The value stored with this method will be available to all scripts.

But, where would I put this? Should I simply make a single autokey script that is dedicated to setting globals?

Will those globals survive a reboot, or will I have to run this script after each boot before the other scripts can use the global string I've created?

Lonnie Best avatar
ae flag
I'm thinking that maybe I should just create an environmental variable in bash, and then simply access that environmental variable from my Autokey scripts. That would probably work, but I'd rather use Autokey best practices instead of this hacky idea.
Lonnie Best avatar
ae flag
I'm also asking for advise here: https://github.com/autokey/autokey/discussions/653
Score:1
cn flag

AutoKey stores global key/value pairs in a dictionary instance of the Store class. When you work with those key/value pairs, you're telling AutoKey to work with that dictionary instance regardless of the script you use to interact with them. Your global key/value pairs are remembered by AutoKey until you either tell AutoKey to change or remove them. Each key/value pair can be accessed from any script. This means that you don't have to go back to the script you used to create a global key/value pair to read it, change it, or remove it.

Lonnie Best avatar
ae flag
So, then, based on what you've said, I can conclude that these global key/value pairs survive reboots. Therefore, I need to create a script that sets these globals, run it once, and then these globals will always be available to my scripts even after I reboot my computer.
Lonnie Best avatar
ae flag
I tested it. It works fantastically. Thank you very much for disabusing my uncertainties.
Little Girl avatar
cn flag
It looks like you already figured it out. Yes, they survive reboots. All store key/value pairs survive reboots. The only difference between local and global key/value pairs is that local key/value pairs are only accessible from the script that created them, whereas global key/value pairs are accessible from any script.
Lonnie Best avatar
ae flag
Yeah, I noticed that. I really like the way it works; its good stuff.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.