How Do I Use KM to Share my Clipboard with AirDrop?

I want to use Keyboard Maestro to evoke AirDrop pop-up window and share my current clipboard, but I don't know how to implement this.

After research, I find this:
https://macosxautomation.com/mavericks/libraries/examples.html
, but I actually don't know how to use it with Keyboard Maestro.

Hello @OscarGong, directly from the clipboard this should not work. To replace the clipboard I use the App Yoink
With this I can cache the different file types and then forward them with AirDrop.

Would that help you?

https://cl.ly/rE2C

Could you describe a bit more what exactly you want to do with this? Are you sending it to your phone? If you are, you could use the universal clipboard.

If you are trying to share with another computer, you could probably send the clipboard to a default text file and then send that? Neither are perfect solutions, but maybe they will help?

Airdrop would be an interesting feature for KM though.

Hi, appleianer.

Thanks, your video is very helpful. I have already using Yoink for several years, I know this function.
But I am seeking a Keyboard Maestro native solution.

1 Like

Hey Oscar,

That library doesn’t work with the Clipboard; it only works with files.

Usage is not very difficult.

Drop the “Sharing Utilities.scptd” script library into this folder:

~/Library/Script Libraries/

Invoke it via AppleScript like so:

use shareLib : script "Sharing Utilities"
use scripting additions

# Must be a LIST of POSIX Paths.
set fileList to {"/Users/myUserName/Downloads/text-utilities.zip"}

begin AirDrop with fileList

I’ve asked the author of the library about making it work with the Clipboard.

-Chris

How can I share files via airdrop in finder by one-click (macro via KM)?

I tried this applescript, saved as application, then click one file or files in finder, execute this application, but nothing happens, how to use it?

Hey Michael,

Did you install the library first?

-Chris

Yes, I drop the “Sharing Utilities.scptd” script library into ~/Library/Script Libraries/.

Hey Michael,

Did you use my script in post #5?

-Chris

Yes, I saved the same script as application in the script editor.

Only change myUserName to the real username.

Then I clicked any file in finder, execute this application, nothing happen.

Hey Michael,

That won't work, because the single listed POSIX Path in the script is arbitrary and has nothing to do with the Finder selection.

What you're looking for is something like this:

----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2018/06/01 20:00
# dMod: 2018/06/02 00:12
# Appl: Finder & Sharing_Utilities_Library (by Shane Stanley)
# Task: AirDrop Selected Items in the Finder
# Libs: Sharing Utilities.scptd
# Osax: None
# Tags: @Applescript, @Script, @Finder, @AirDrop, @Selected, @Items
----------------------------------------------------------------
use shareLib : script "Sharing Utilities"
use scripting additions
----------------------------------------------------------------

# Acquire the Finder-selection as a list of aliases.
tell application "Finder"
   set finderSelectionList to selection as alias list
   if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
end tell

# Transform the aliases of the Finder-selection to POSIX Paths.
repeat with theFile in finderSelectionList
   set contents of theFile to POSIX path of theFile
end repeat

begin AirDrop with finderSelectionList

----------------------------------------------------------------

Unfortunately I can't test this, because my 17" Mid-2010 MacBook Pro doesn't support AirDrop.

Let me know if it works for you.

-Chris

I tried, but there's an error:

The variable fileList is not defined.
The variable fileList is not defined. (-2753)

Hey Michael,

Whups. That should be fixed in the script now.

-Chris

The code no longer works.

Script Editor says:

Syntax Error
Can’t get script "Sharing Utilities".
1 Like

Hey Martin,

Did you install the script library?

If not see the link in the very first post of the thread and search the page for ‘download’.

-Chris

Oh. No. I did not know I had to install a script library. Now I know a little bit more about AppleScript then. I understand the error report better. Sorry for my ignorance.
For the airdrop function, I've found an alternative way in BTT. Just click the menu bar item:
image

It's odd I need a second identical action to make it work. But it works.