Drop Zone
Drop Zone¶
A popover that accepts dropped files, copies their paths to the clipboard, and reports through a global hotkey.
What it shows¶
on_dropon a container viewapp.clipboard@app.hotkey()andapp.notify()- A context menu with an icon and a shortcut

import nib
def main(app: nib.App):
app.title = "Drop Zone"
app.icon = nib.SFSymbol("tray.and.arrow.down")
app.width = 280
app.height = 180
status = nib.Text("Drop files here", foreground_color=nib.Color.SECONDARY)
paths_text = nib.Text("", font=nib.Font.CAPTION)
dropped = []
def handle_drop(paths):
dropped[:] = paths
status.content = f"{len(paths)} dropped"
paths_text.content = "\n".join(paths[-3:])
app.clipboard = "\n".join(paths)
@app.hotkey("cmd+shift+d")
def announce():
app.notify("Drop Zone", status.content)
def copy_paths():
app.clipboard = "\n".join(dropped)
app.menu = [
nib.MenuItem("Copy paths", on_click=copy_paths, icon="doc.on.doc"),
nib.MenuDivider(),
nib.MenuItem("Quit", on_click=app.quit, shortcut="cmd+q"),
]
app.build(
nib.VStack(
controls=[
nib.SFSymbol("tray.and.arrow.down", scale="large"),
status,
paths_text,
],
spacing=8,
padding=24,
on_drop=handle_drop,
)
)
nib.run(main)
Walkthrough¶
The drop target¶
on_drop=handle_drop on the VStack makes the whole popover a drop target. The callback receives one string per dropped item: a path for a file or folder, the URL for a link, the text for selected text. See Drag and drop.
Clipboard¶
app.clipboard = text writes every dropped item to the clipboard. The "Copy paths" menu item copies them again the same way.
Hotkey and notification¶
@app.hotkey("cmd+shift+d") registers a global shortcut. It fires with the popover closed once the app has Accessibility access; see Hotkeys. The handler posts a notification with app.notify(title, body).
Related¶
- Drag and drop
- Clipboard
- Notifications
- App:
hotkey,clipboard,notify,menu