Arrays and Arrays and Arrays and Somebody Please Help Me Arrays

I've read extensively in the Wiki, on the website, and strange corners of the internet. Climbed the mountains of Himilayas. Swam the watery deeps of Mongolian caves. I just can't.

Could some wise person please translate this C code?

int myArray [10];
int myIndex = 5;
int myValue;

myArray [Index] = myValue;
int myResult = myArray[9];

Thank you, Kindly. I'm so confused. :crazy_face:

I don't program in C, but the first thing I want to say is that there are no integer arrays in KM. There are only strings, but KM allows you to fetch the Nth element of a string using and index that looks like a standard programming language index into a numeric array.

And the second think I want to say is that KM lets you fetch array elements from a string, but not assign elements the way you can in C. There are workarounds. There's a workaround using Javascript, one using shell commands, and one using macros. If you give us more context about your problem we might be able to give you the best answer. Fore some more information you could check this post:

I'm a little confused by your screenshot. If you show the action where you are trying to use that string, I can probably correct you. But since I don't know the context, I'm not able to provide the solution.

1 Like

Hi @Sleepy, thank you for your response. I'll try a Dictionary. Let's say the Dictionary is called "Ferrets", a key called "Name", and a value called "Length".

  1. How would I please create the dictionary?

  2. How would I please add one pair ("Joey", "11")?

  3. How I please access the Value of Ferret_Farm for key "Joey"?

Thank you, my friend.

You don't create a dictionary explicitly. When you assign a value to a key in dictionary, it's created. When you assign an empty string to a dictionary's key, that element vanishes forever.

Your question seems to indicate a slight misunderstanding. In your opening statement you said "a key called "Name", and a value called "Length"." but in fact the key in this question is "Joey" and its value is "11". There is indeed nothing actually called "Name" or "Length". So your terminology is slightly incorrect.


The most common way to do that is like this:


However most of the time you will want to specify the key as a variable, so you do it like this:


Notice how the variable, in this case MyKey, is inserted. It's an odd syntax, but you'll get used to it.

It took me several hours, or maybe days, to get used to dictionaries. But I'm glad they exist. They are pretty powerful.

Hey Bill,

You can do something like this.


Extract An Element of An Array By Variable v1.00.kmmacros (8.4 KB)
Keyboard Maestro Export