Insert Text Into Restricted Field, v5.0

MACRO DEMONSTRATION

The following animated gif demonstrates one possible use of this macro: a password confirmation field that blocks the paste of a new password (Grrr...).

ITIRF-3

Refer to the MACRO USE section for more information.


MAIN DIALOG

When the macro is triggered, the following dialog appears. At first glance it may seem complex, but often the default values can be confirmed and used. If settings are changed, they are preserved for subsequent use.


PURPOSE

This macro provides a method to "paste" text into a field that is normally restricted, intentionally (e.g., a password confirmation field*) or otherwise (e.g., VNC apps; OBS when interacting with a source). For many of these fields, the Keyboard Maestro action Insert Text by Typing will suffice. However, in cases when the web page or macOS app intercepts the Keyboard Maestro trigger, and/or in cases where the text must be pasted more slowly, this macro can be used.

*When the text is long (e.g., with secure passwords copied from a password manager) this can be particularly aggravating.


MACRO USE

  • Move the focus away from the restricted field (web page or macOS app).

  • Optionally copy a text string, e.g., a complex password.

  • Trigger this macro; the main dialog will appear that includes the clipboard text and five macro settings.

  • Optionally modify the text and/or settings: Text to Insert (default = clipboard); Search and Replace the text before inserting (default = unchecked); RegEx Pattern, JavaScript syntax, to use if applying search and replace (default = /:|\//g, "-")*; Wait before inserting (in seconds; default = 5); Method (default = Insert text by typing); Delay between characters (in hundredths of seconds; default = 0).

  • Select the Insert Text button.

  • A countdown timer, that begins at Wait seconds, will appear.

  • During the countdown*, move the timer if necessary, return the focus to the restricted field and wait for the timer to expire; the text will then be entered by the macro. The submarine sound will be heard when the text insertion is complete.

    * The countdown timer includes three buttons for optional use: Cancel, Reset, and Restart; the first will cancel the macro (esc will do the same), the second will reset the countdown, and the third will restart the macro (presumably to change one of the dialog settings).

Timer


SETTINGS

The Search and Replace, RegEx Pattern, Wait, Method, and Delay settings are saved for subsequent macro executions; however, the dialog includes are Restart w/ Default Settings button.

The Text to Insert is not preserved; it always defaults to %SystemClipboard% but can be set to the %TriggerClipboard% from a Clipboard History Switcher or Named Clipboard Switcher calling macro. (A calling macro is supplied below.)


ACKNOWLEDGEMENTS

HTML/JavaScript code within this macro was adapted from: Simplistic Countdown Timer, by @troy. In turn, that code was adapted from Keyboard Maestro Actions that @perternlewis supplied in this post.


TESTED WITH

β€’ Keyboard Maestro 11.0.3
β€’ Sequoia 15.4.1 (24E263)/MacBookPro18,2
β€’ Mojave 10.14.16/Macmini6,2
β€’ High Sierra 10.13.6/iMac11,1445


VERSION HISTORY

( expand / collapse )

1.0 - Initial version

1.1 - Fixed typographical errors in this comment. No functional changes to the macro.

1.2 - Changed the timer (i.e., custom HTLM Prompt) to deselect Asynchronously.

2.0
a) Enhanced the timer: i) improved appearance, and ii) added Cancel, Reset and Restart buttons.
b) Improved the instructions in the initial dialog.
c) Moved the persistant values from individual global variables to a dictionary.

3.0
a) Changed the name from Paste Into Restricted Field to Insert Text Into Restricted Field.**
**b) Added the Method setting and corresponding logic.
c) Deleted the secondary trigger and added the Restart Macro with Default Settings button.
d) Improved the timer JavaScript by making the code more readable. Also, the timer is now centered.
e) Updated the dialog to indicate the number of lines in the clipboard (if greater than 1).
f) Settings have been moved to the top of the macro; dialog adjusted to properly display these values.

4.0
a) Added logic to determine if this macro is being called by a macro that is supplying the %TriggerClipboard% (from the Clipboard History Switcher). A calling macro is also supplied.

b) Modified the main dialog:

  • added a Clipboard History Switcher button
  • added Settings: Search and Replace and RegEx Pattern
  • Added line and character count for Text to Insert

c) Modified the timer:

  • changed format 0:00:00 to 0:00
  • added escape press to be equivalent to Cancel button
  • When timer first appears, a light green backgound appears (to draw attention to the timer); same light green is used when the Reset button is pressed;
  • background now changes to yellow when countdown is 0:05 seconds or less
  • added some space between buttons

d) Converted some IfThenElse actions to Switch/Case actions

e) Simplified the logic for saving Wait, Method, Delay

5.0
a) Modified the AppleScript that displays the Clipboard History Switcher. Using a method provided by @Nige_S, it now functions as expected when it had been previously displayed and minimized.

b) Added an option to display the Named Clipboard Switcher.


Download: Insert Text Into Restricted Field.kmmacros (65 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 15.4.1 (24E263)
  • Keyboard Maestro v11.0.3

Below is a calling macro that can be used to trigger the above macro from the Clipboard History Switcher or the Named Clipboard Switcher; it provides an easy method to insert the text from any of the entries in the Clipboard History Switcher or Named Clipboard Switcher.

After downloading and installing the following macro, check the gear menu within the Clipboard History Switcher selected entry.

Download: 𝘀𝘒𝘭𝘭 Insert Text Into Restricted Field.kmmacros (3.9 KB)

Macro-Image


2 Likes

I've updated the OP with Version 3.0 of Insert Text Into Restricted Field:

  • Changed the name from Paste Into Restricted Field to Insert Text Into Restricted Field.

  • Added the Method setting and corresponding logic.

  • Deleted the secondary trigger and added the Restart Macro with Default Settings button.

  • Improved the timer JavaScript by making the code more readable. Also, the timer is now centered.

  • Updated the dialog to indicate the number of lines in the clipboard (if greater than 1).

  • Settings have been moved to the top of the macro; dialog adjusted to properly display these values.

1 Like

I've updated the OP with Version 4.0 of Insert Text Into Restricted Field:

  • Added logic to determine if this macro is being called by a macro that is supplying the %TriggerClipboard% (from the Clipboard History Switcher). A calling macro is also supplied.

  • Modified the main dialog:

    • added a Clipboard History Switcher button
    • added Settings: Search and Replace and RegEx Pattern
    • Added line and character count for Text to Insert
  • Modified the timer:

    • changed format 0:00:00 to 0:00
    • added escape press to be equivalent to Cancel button
    • When timer first appears, a light green backgound appears (to draw attention to the timer); same light green is used when the Reset button is pressed;
    • background now changes to yellow when countdown is 0:05 seconds or less
    • added some space between buttons
  • Converted some IfThenElse actions to Switch/Case actions

  • Simplified the logic for saving Wait, Method, Delay

2 Likes

Very cool thanks for sharing this with us.

1 Like

I've updated the OP with Version 5.0 of Insert Text Into Restricted Field:

1 Like