app.share - macOS Sharing Services API
Use NSSharingService to invoke the system sharing panel (AirDrop, Mail, Messages, etc.).
Methods
app.share.show(items)
Show the system sharing panel, allowing the user to choose a sharing method.
Parameters:
items(string|array) - content to share:- File paths (automatically converted to file URLs)
- HTTP/HTTPS links (automatically converted to URLs)
- Plain text
Returns: boolean, error
-- Share a single file
app.share.show("/path/to/file.pdf")
-- Share multiple files
app.share.show({"/path/to/a.png", "/path/to/b.png"})
-- Share text
app.share.show("Hello, World!")
-- Share a URL
app.share.show("https://example.com")
-- Mixed content
app.share.show({"/path/to/file.txt", "https://example.com"})
app.share.services(items?)
List available sharing services.
Parameters:
items(string|array, optional) - content to share (affects available services list)
Returns: array<table> - each item contains:
name(string) - service identifier nametitle(string) - service display title
local services = app.share.services()
for _, s in ipairs(services) do
app.log.info(s.name .. " → " .. s.title)
end
-- View available sharing services for a specific file
local services = app.share.services({"/path/to/photo.jpg"})
app.share.sendTo(serviceName, items)
Share content directly through a specific service (without showing the panel).
Parameters:
serviceName(string) - service name, supports:- Built-in names:
"email","message","airdrop" - Service titles (obtained from
services())
- Built-in names:
items(string|array) - content to share
Returns: boolean, error
-- Share via email
app.share.sendTo("email", {"/path/to/report.pdf"})
-- Share via AirDrop
app.share.sendTo("airdrop", {"/path/to/photo.jpg"})
-- Share via Messages
app.share.sendTo("message", "Check this out: https://example.com")
Description
- The sharing panel appears near the mouse cursor position
- When using
sendTo()with built-in service names, there’s no need to callservices()first - Built-in service name mappings:
email→ Mail,message→ Messages,airdrop→ AirDrop - File paths are automatically detected and converted to file URLs
- Strings starting with HTTP/HTTPS are automatically converted to URLs
Examples
Share Selected Files via Context Menu
function MyPlugin:handleShare(context)
local files = context.selectedFiles
if #files == 0 then
app.dialog.alert("Note", "Please select files first")
return
end
app.share.show(files)
end
Send Files via Email
function MyPlugin:handleEmailFiles(context)
local files = context.selectedFiles
local ok, err = app.share.sendTo("email", files)
if not ok then
app.log.error("Share failed: " .. (err or "unknown"))
end
end