Make a LaunchBar Action paste the selected item (from a variable)

General discussions about LaunchBar
Post Reply
Jono
Rank 4
Rank 4
Posts: 161
Joined: Mon Feb 25, 2008 11:25 am
Location: UK
Contact:

Make a LaunchBar Action paste the selected item (from a variable)

Post by Jono » Tue Jan 30, 2018 12:07 pm

I've managed to cobble together this script (with a lot of help at the Keyboard Maestro forum). It shows Keyboard Maestro's named clipboards

Image



When hitting Enter with one of the selected items (clipboard entries) I want to paste it into whatever's at the front.

But I'm struggling getting it to grab the clipboard entry (variable) and paste it into whatever app is at the front/activated. Here is the code

Code: Select all

#!/bin/bash

osascript -l JavaScript <<JXA_END 2>/dev/null
function run() {
   'use strict';

   // clipboardNames :: () -> [String]
   const clipboardNames = () =>
      ObjC.deepUnwrap(
         \$.NSArray.arrayWithContentsOfFile(
            \$(
               '~/Library/Application\ Support/' +
               'Keyboard\ Maestro/Keyboard\ Maestro' +
               '\ Clipboards.plist'
            )
            .stringByStandardizingPath
         )
      )
      .map(clip => clip.Name)
      .sort();

   const
      kme = Application('Keyboard Maestro Engine'),
      kvs = clipboardNames()
      .map(clipboardNumber => ({
         name: clipboardNumber,
         title: kme.processTokens(clipboardNumber + ': %NamedClipboard%' + clipboardNumber + '%'),
         subtitle: ('Keyboard Maestro: ' + clipboardNumber),
         icon: 'Clipboard.icns'
      }));

   return JSON.stringify(kvs, null, 2); //:: [{name::String, title::String, subtitle::String, icon::String}]
}
JXA_END



I guess I need to take the variable of the selected clipboard item and paste it with something like this

Code: Select all

LaunchBar.paste('%NamedClipboard%' + clipboardNumber + '%');


But I haven't been able to get the script to paste clipboard entry. Does anyone know how to do this? :)

Post Reply