No internet connection
  1. Home
  2. How to

User select from a list of existing named clipboard items

By Andrew Sherman @Andrew_Sherman
    2021-02-02 14:22:26.522Z

    I'm trying to set up a macro that allows me to quickly access clipboard items I use frequently. I need a list of constants (either one-word strings, could be numbers or even full sentences). Similar to named clipboards in Keyboard Maestro.

    Example clipboard items:

    • VAT Number 1234567
    • Company Reg number 123456789
    • Address: 12 Road Name, Suburb, Country 1234

    What I want to do is use a keyboard shortcut to trigger a window or pop-up that asks me to choose one of the items (ideally the window would be where the mouse is, but not essential!), and once I've selected an item either by clicking on it or using the arrow keys and return, then the text is typed/pasted into whichever application is currently active.

    Workflow example:

    • Press hotkey trigger
    • Make selection of named clipboard item
    • The selected text item is typed into the active app.
    Solved in post #3, click to view
    • 3 replies
    1. A
      Andrew Sherman @Andrew_Sherman
        2021-02-02 14:34:28.000Z

        I'm trying with the following actions:

        • Select from list
        • Type text
          But I'm getting an error "expected string but got object"
        1. Hi Andrew,

          The following script should do the trick:

          
          //Define the text items
          var items = [
              {
                  name: 'VAT Number',
                  value: '1234567'
              },
              {
                  name: 'Company Reg number',
                  value: '123456789'
              },
          ];
          
          //Record which app is focused
          var activeAppBundleID = sf.ui.frontmostApp.activeBundleID;
          
          //Ask the user which item to use
          var selectedItem = sf.interaction.popupSearch({
              items: items,
              title: 'Please select an item to copy',
          }).item;
          
          //Re-activate the originally focused app
          sf.ui.app(activeAppBundleID).appActivate();
          
          //Type the text
          sf.keyboard.type({ text: selectedItem.value });
          
          Reply1 LikeSolution
          1. AAndrew Sherman @Andrew_Sherman
              2021-02-02 15:39:14.293Z

              Perfect, thank you.