REORDER: Subroutine Parameters

In addition to a macro to reorder Switch/Case groups & User Input prompts, here's one that will reorder Subroutine input parameters.


PLEASE NOTE

Changes to the order of a subroutine's input parameters will also change their order in any existing subroutine callers. Be sure to update these callers so that their parameters and values correspond.

To help with this, @_jims has cleverly created two companion macros that can be found HERE.


Usage:

While editing your subroutine, or with it selected in the Editor's Macros list, trigger this macro. A prompt will appear:

You can now drag-and-drop the parameters up and down within the prompt and click OK to submit it. The selected macro will be replaced with your newly rearranged version. If you change your mind, just use KM's Undo feature (press ⌘Z twice).

Download:

Reorder Subroutine Parameters.kmmacros (84 KB)

Macro screenshot

6 Likes

Although I don't do this task often, this macro is really helpful when needed. Thank you!


@noisneil noted above...

Changes to the order of a subroutine's input parameters will also change their order in any existing subroutine callers. Be sure to update these callers so that their parameters and values correspond.

To address this issue, I created two macros that can be used after using Reorder Subroutine Parameters:

Download: After Reorder Update Execute a Subroutine action.kmmacros (77 KB)

Usage:

  1. Navigate to a calling macro.
  2. Select the corresponding Execute a Subroutine action.
  3. Trigger this macro. The selected action will not be changed; instead a new Execute a Subroutine action, with parameter values correspondingly reordered, will be inserted immediately above the selected action.
  4. After confirming that the new action is as expected, manually delete the original Execute a Subroutine action.
  5. Repeat this process for all calls to the reordered subroutine.

Download: Purge Subroutine Reorder Information.kmmacros (73 KB)

Usage:

After addressing all callers, trigger this macro. A dialog like the following will appear.

Use the Purge checkbox to delete any reorder information that no longer needed.


If you'd like to test the reorder process, here's a file that contains two subroutine macros (Sub_Example1; Sub_Example2) and two callers (Sub_Example1 𝘀𝘒𝘭𝘭𝘦𝘳; Sub_Example2 𝘀𝘒𝘭𝘭𝘦𝘳) .

Examples.kmmacros (117.8 KB)


IMPORTANT NOTE

The latest version of Reorder Subroutine Parameters is required; it saves the reorder information in a dictionary that is used in the two macros above.

2 Likes