Share selected file with AirDrop

I am trying to configure a keyboard shortcut (Fn + A) to open the airdrop share window with the selected file.

How can I do this with BTT?

You can do this with an "Run AppleScript (blocked)" Action:

use framework "Foundation"
use scripting additions

tell application "Finder"
	set temp to selection as alias list
	if (count of temp) is 1 then
		set thePath to POSIX path of item 1 of temp
		set theURL to current application's |NSURL|'s fileURLWithPath:thePath
		set theService to current application's NSSharingService's sharingServiceNamed:(current application's NSSharingServiceNameSendViaAirDrop)
		theService's performSelectorOnMainThread:"performWithItems:" withObject:{theURL} waitUntilDone:false
	end if
end tell

Note:

  • You must enable accessibility for BTT to control the finder
  • Two processes remain permanently in the Activity Monitor after the first execution:

    However, this is also the case if you execute AirDrop normally via the Finder menu and seems to be a bug in macOS:
  • If nothing or more than one entry is selected in the current Finder window, nothing happens
1 Like

While this is a great solution, it is also pretty advanced. In general I would recommend to use the Apple Shortcuts app instead where you can easily do that:

BetterTouchTool can execute shortcuts defined there using the "Run Shortcut from Shortcuts App" action.