Skip to main content
deleted 26 characters in body
Source Link
lnaef
  • 41
  • 2

You can do so using Hammerspoon. It's not completely automatic since you still have to select your phone.

opendrop doesn't work on the iPhone unfortunately.

I've written a blog post about thisI've written a blog post about this

Add the following to your init.lua


local hex_to_char = function(x)
  return string.char(tonumber(x, 16))
end

local unescape = function(url)
  return url:gsub("%%(%x%x)", hex_to_char)
end


hs.urlevent.bind("airdrop", function(eventName, params)
    local file = unescape(params["f"])
    print(file)
    local url = hs.sharing.fileURL(file)
    local ad = hs.sharing.builtinSharingServices.sendViaAirDrop
    local s = hs.sharing.newShare(ad)
    s:shareItems({url})
end)

This will construct an endpoint to the hammerspoon Custom URL that can receive filenames as input.

Then you can create a script like this

#! /usr/bin/bash

rawurlencode() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               printf -v o '%%%02x' "'$c"
     esac
     encoded+="${o}"
  done
  REPLY="${encoded}" 
}

rawurlencode "$@"

/usr/bin/open -g "hammerspoon://airdrop?f=${REPLY}"

This will URL-encode the input and send it to the airdrop custom URL which we've registered with hammerspoon.

Save this somewhere as airdrop file in your $PATH, chmod +x it (make executable), and then you can airdrop <myfile>

You can do so using Hammerspoon. It's not completely automatic since you still have to select your phone.

opendrop doesn't work on the iPhone unfortunately.

I've written a blog post about this

Add the following to your init.lua


local hex_to_char = function(x)
  return string.char(tonumber(x, 16))
end

local unescape = function(url)
  return url:gsub("%%(%x%x)", hex_to_char)
end


hs.urlevent.bind("airdrop", function(eventName, params)
    local file = unescape(params["f"])
    print(file)
    local url = hs.sharing.fileURL(file)
    local ad = hs.sharing.builtinSharingServices.sendViaAirDrop
    local s = hs.sharing.newShare(ad)
    s:shareItems({url})
end)

This will construct an endpoint to the hammerspoon Custom URL that can receive filenames as input.

Then you can create a script like this

#! /usr/bin/bash

rawurlencode() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               printf -v o '%%%02x' "'$c"
     esac
     encoded+="${o}"
  done
  REPLY="${encoded}" 
}

rawurlencode "$@"

/usr/bin/open -g "hammerspoon://airdrop?f=${REPLY}"

This will URL-encode the input and send it to the airdrop custom URL which we've registered with hammerspoon.

Save this somewhere as airdrop file in your $PATH, chmod +x it (make executable), and then you can airdrop <myfile>

You can do so using Hammerspoon. It's not completely automatic since you still have to select your phone.

opendrop doesn't work on the iPhone unfortunately.

I've written a blog post about this

Add the following to your init.lua


local hex_to_char = function(x)
  return string.char(tonumber(x, 16))
end

local unescape = function(url)
  return url:gsub("%%(%x%x)", hex_to_char)
end


hs.urlevent.bind("airdrop", function(eventName, params)
    local file = unescape(params["f"])
    print(file)
    local url = hs.sharing.fileURL(file)
    local ad = hs.sharing.builtinSharingServices.sendViaAirDrop
    local s = hs.sharing.newShare(ad)
    s:shareItems({url})
end)

This will construct an endpoint to the hammerspoon Custom URL that can receive filenames as input.

Then you can create a script like this

#! /usr/bin/bash

rawurlencode() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               printf -v o '%%%02x' "'$c"
     esac
     encoded+="${o}"
  done
  REPLY="${encoded}" 
}

rawurlencode "$@"

/usr/bin/open -g "hammerspoon://airdrop?f=${REPLY}"

This will URL-encode the input and send it to the airdrop custom URL which we've registered with hammerspoon.

Save this somewhere as airdrop file in your $PATH, chmod +x it (make executable), and then you can airdrop <myfile>

Source Link
lnaef
  • 41
  • 2

You can do so using Hammerspoon. It's not completely automatic since you still have to select your phone.

opendrop doesn't work on the iPhone unfortunately.

I've written a blog post about this

Add the following to your init.lua


local hex_to_char = function(x)
  return string.char(tonumber(x, 16))
end

local unescape = function(url)
  return url:gsub("%%(%x%x)", hex_to_char)
end


hs.urlevent.bind("airdrop", function(eventName, params)
    local file = unescape(params["f"])
    print(file)
    local url = hs.sharing.fileURL(file)
    local ad = hs.sharing.builtinSharingServices.sendViaAirDrop
    local s = hs.sharing.newShare(ad)
    s:shareItems({url})
end)

This will construct an endpoint to the hammerspoon Custom URL that can receive filenames as input.

Then you can create a script like this

#! /usr/bin/bash

rawurlencode() {
  local string="${1}"
  local strlen=${#string}
  local encoded=""
  local pos c o

  for (( pos=0 ; pos<strlen ; pos++ )); do
     c=${string:$pos:1}
     case "$c" in
        [-_.~a-zA-Z0-9] ) o="${c}" ;;
        * )               printf -v o '%%%02x' "'$c"
     esac
     encoded+="${o}"
  done
  REPLY="${encoded}" 
}

rawurlencode "$@"

/usr/bin/open -g "hammerspoon://airdrop?f=${REPLY}"

This will URL-encode the input and send it to the airdrop custom URL which we've registered with hammerspoon.

Save this somewhere as airdrop file in your $PATH, chmod +x it (make executable), and then you can airdrop <myfile>