Skip to content

Instantly share code, notes, and snippets.

@alanhg
Created December 14, 2021 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanhg/b6ac5adfb4c029fe44d933f998b9fbaa to your computer and use it in GitHub Desktop.
Save alanhg/b6ac5adfb4c029fe44d933f998b9fbaa to your computer and use it in GitHub Desktop.
airdrop-share.scpt
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
-- This script brings up the AirDrop dialog for the selected file(s) in Finder (window or desktop)
-- Isaac Nelson 17 Jan 2018
-- Vastly improved by implementing Aviral Bansal's fix for UI scripting slowness: https://stackoverflow.com/a/36370637/9278116
-- Updated 28 Mar 2018 to make it work in an Automator workflow
-- Updated 17 Dec 2019 to fix issue with comparison between parentPath and desktopPath
tell application "Finder"
set sel to get the selection
if (sel is {}) then
log "Nothing selected! Can't proceed"
return
end if
set parentPath to (container of item 1 of sel) as alias
set desktopPath to (path to desktop folder)
if desktopPath is equal to parentPath then reveal sel
end tell
tell application "System Events"
tell process "Finder"
set shareButton to (first button whose description is "Share") of toolbar 1 of window 1
ignoring application responses
click shareButton
delay 0.1
end ignoring
end tell
end tell
do shell script "killall System\\ Events"
tell application "System Events"
click (menu item "AirDrop") of menu 1 of shareButton
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment