MACRO: Toggle Between Macros and Maintain Scroll Position

MACRO: Toggle Between Macros and Maintain Scroll Position

OUTDATED.

KM now automatically maintains the scroll position, so you don't need that portion of this macro anymore.

Instead, use this version: MACRO: Toggle Between Macros


UPDATED Version 2.0:

Now makes use of a common set of Sub-Macros to save and restore scroll position. These Sub-Macros can be used by other macros, which can contribute to, and make use of the saved Scroll Positions.

NOTE to users of @JMichaelTX's v1.1 version: Very shortly I will be introducing some new sets of macros that will make it extremely likely that either he or I will want to re-do his work. So for now, v2.0 of this macro does not include his changes. Hopefully that will change very soon.

Toggle Between Macros and Maintain Scroll Position.v2.0.zip (15.2 KB)

This macro switches you between editing one macro and another. It saves and restores the vertical scroll position, so you don't have to keep scrolling around.

The scrolling is not instantaneous, but I think it's quick enough - you be the judge.

This is not the be-all and end-all solution. It's only good if you're switching back and forth, multiple times. If you are working on one macro and switch to another without using this macro, your scroll position is not saved.

I'd like to come up with a complete solution, but at this time, I can't think of one. Any ideas, feel free to share!

7 Likes

Hey Dan,

Good work figuring out the scroll position.  :smile:

-Chris

I learned from the best! :slight_smile:

Nice job, Dan! :thumbsup:

The scrolling speed is fine for me.

Thanks! Yes, the speed is fine for me also.

If you can think of a way to improve it, let me know. Especially, a way to save the scroll position before moving to another macro when not using using this macro. I don't think there's a way, but I sure wish there was!

Dan, here are some thoughts that you can consider or ignore:

  • Document KM Variables that must persist (not be deleted)
    • The user of the macro needs to know which variables not to delete
    • Consider using a prefix for all KM Variables that should not be deleted, so that they are easily identified by:
      • Visual inspection in the KM Preferences > Variables tab
      • Search by script
      • For examle, I use "DND__". I know you don't like that prefix, and that's fine. Make one of your own design.
    • A while back there was a lot of interest in how to cleanup unused Variables
    • Here is one macro that does that: [KM] DELETE All Variables Except Those on Keep List
      .
  • In your scripts, document at the top which KM Variables are required and which are set (if any).

Here’s my current philosophy, however I’ve been known to forget something every now and then, so if my code doesn’t match up to this, let me know:

If a macro does not fail, then I clean up every variable that needs to be cleaned up. If a macro fails, the Cleanup Variables section never gets called, which is fine by me, because I might want to look at the values.

With that said, I think you make a valid point. I’m not a fan of “DND__”, but I could live with it.

The real issue is traction - getting other people to follow the same standards. Well, maybe it’s not the issue - it doesn’t stop me from doing it. I’ll have to think about it.

And of course, this kind of discussion makes me wish I’d finish my code for determining what variables are created/used in a macro. If I could get that done, imagine what we could do. We could produce a list of all variables, and cross-reference them to the macros that create/use them. Wouldn’t that be totally cool?

Putting aside the prefix issue for the moment, my main request is to document which KM Variables must persist (not be deleted, like by the user when cleaning up his/her variable list).

Now, about the prefix. It does not matter so much what the prefix is, as it does to use a prefix, and hopefully in all macros. While I'd prefer there be one prefix we could all use, it is not required. Each macro developer could even have a prefix he/she uses. I like the "DND__" because it really jumps out at me when I view my KM variable list, but is hidden from the user in Prompt for Input. But that's just me. Use whatever you like.

I plan to mod my [KM] DELETE All Variables Except Those on Keep List macro to support as many prefixes as you like to NOT delete.

Dan, again a great macro I'm already making good use of.

I found one thing more I'd like it to do, so here's my enhancement.
Please feel free to use or ignore as you see fit.
I tried to follow your style as best as I could determine it.

VER: 1.1 2016-08-12 By JMichaelTX
• ADD Option to select Macro to Switch To
• Simply hold down ("Long Press Key") either Trigger Key for at least 0.5 sec
• Use the arrow keys to highlight the macro, then press RETURN to select it.

My thanks to Chris (@ccstone) for his excellent script:
Open the Keyboard Maestro Editor Macro Edit History menu


MACRO:   Toggle Between Macros and Maintain Scroll Position VER 1.1


#### DOWNLOAD:
<a class="attachment" href="/uploads/default/original/3X/e/a/eaf57554ac4ec341a204440e97c0b59aa131677c.kmmacros">Toggle Between Macros and Maintain Scroll Position VER 1.1.kmmacros</a> (50 KB)
**Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.**

---



![image|575x1999](upload://rygngVsfKR33QfAebmqGmtqQQk9.png)
2 Likes

I think this is exactly what I was hoping for. I’m just not positive the best way to use it, fingers, mouse, keyboard-wise.

Can you tell me the steps, for the long press? I know you hold down the keys for a half second. When the list pops up, what do you do? Scroll with the arrows and hit enter?

Exactly.

Unfortunately you have to use the RETURN key to select the macro from the list for now, because Pausing for RETURN is the only way I know to pause.

If would be great if there was some way to pause until the popup list was closed.

Well, I have a solution for that, and dammit, I'm going to stop going off on rabbit trails and finish it.

Great! I look forward to seeing it.

I just uploaded version 2.0 of this macro. Give me a little time to upload the remaining macros, then we can discuss re-incorporating your changes into the new version.

I didn't include your changes in this version, because I was fairly sure we'll want to re-work them, to some degree or another, in light of other macros I'll upload shortly. Maybe not, but let's see.

I'll get back to you soon. However, if I forget, hit me up again. And if I do forget, don't feel slighted - with everything rolling around in my head right now, some things are bound to roll right out my ears and drop on the ground. :blush: Especially after my fiasco yesterday...

Dan, thanks a lot for this macro useful of course as help in KM editor navigation and useful too in improving my learning of AppleScript :slight_smile:

1 - I experience errors like


and hopefully find why, so I share :wink:

It is due to localization troubles in AppleScript - as I use a French configuration - in the bidirectional conversion of numeric values <=> text, needed by KM only text variables, e.g. "0.7521263669501823" <=> "0,7521263669501823".

For a more localization bullet proof transcoding, I suggest to change beginning of AppleScript code of Macro Scroll Position - Store for Current Macro (Sub-Macro) to

2 - BTW Macro Scroll Position - Restore for Current Macro (Sub-Macro) is not (yet) called :wink:

-Alain

Awesome - I like it. I'll do it.

It's not? This is what I see:

Are you saying it's different on yours?

This is that I see

I.e. the macro Toggle Between Macros and Maintain Scroll Position don't use macro Macro Scroll Position - Restore for Current Macro (Sub-Macro) of your zipped package.

I guess I don’t understand what you were saying then.

Dan, I'm good with that. I'll wait until the dust settles on your new round of macros before making any further comments or changes.

I agree with that. I posted my macro mainly for Dan's benefit, but if you are using it I suggest you now switch to Ver 2 of Dan's macro.

1 Like

I wish I could figure out how to get the list of macros that show up in the list you get when you click the “clock” icon. I don’t see that stored anywhere, at least not that I noticed.

Got any ideas?

BTW, good idea to wait for the dust to settle. I’m learning a bunch of new things today. :slight_smile:

Oh, and I hope you notice, all of the macros I uploaded today use “DND__” in front of variables I want to persist. And it’s funny - the moment I actually started using the prefix, I loved it. I thought it was going to look fugly, but it doesn’t at all. Guess I should have given in a long time ago! :blush:

OK, what other suggestions have you made that I blew off? :slight_smile: