Increment a variable by 1 and put it in the name of a text

copy_book.kmmacros (4.6 KB)

I can't figure out how to increment a variable by 1 and put that variable name in some text. I looked at this documentation

but the action (calc) is not available. I can't use the for each action because i do not have a preexisting collection of objects. I tried putting increment i by 1 into the action 'set variable' but that didn't work.

Try this version out and see if it doesn't do what you want:

copy_book.kmmacros (4.6 KB)
04 PM

Don't worry that the Set Variable action has the + 1 part in red; that just means the i variable hasn't been created yet. Run the macro once to create the variable and it will start being shown in black.

The error message I’m getting is

write files action failed to read source image
while executing write file to clipboard

which leads me to believe that my last action is not correct.

I just tested this, and when I left the pauses on, it seemed to copy macro actions to the desktop instead of the expected images for some reason, which resulted in the same error. However, when I disabled the pauses, it all worked as expected, with the added benefit of being much faster. The only further change I made to make the resulting files display properly in the Finder was explicitly adding the .png extension to the Write File action:

copy_book.kmmacros (4.6 KB)
30 PM

no, I’m still getting the same error. I tried the attached macro but I’m not sure if that’s yours or mine. Also, I have a mac. Does ‘windowname’ work with the mac? Is there anyway you can upload the exact macro that you got to work. Also, when I eliminate the last action I get an error at the set variable part.

That version I just uploaded was the one I got working, but I can see how keeping the same name would be confusing, so this latest version has a new number to make it clearer. I also replaced the pauses with actions to ensure that the macro pauses until the clipboard contains the screenshot before writing the clipboard to a file, which should hopefully help with your issue.

copy_book 1.1.kmmacros (4.3 KB)
27 PM

KM is only available for the Mac, and %WindowName% is a KM-specific text token that contains the name of the front-most window, so yes, it definitely works :slightly_smiling_face:

thanks that did it. the problem was that in the screen shots you provided i could not completely see what was in the path box. the second problem was that i didn’t use the macro you uploaded but a different one.

1 Like