Send to Your AI

@rebind / send-to-your-aiv0.1.3Public

Select text anywhere and press one key to paste it into ChatGPT, Claude or Codex with your prompt in front.

Files

Older release. Installs get 0.1.3.

main.luau1.9 KB

-- Send to Your AI: copy the selection, switch to your AI app, and paste it
-- with your prompt in front. It stops there, so you send it yourself.

local IS_MAC = _REBIND.platform == "macos"
local MOD = if IS_MAC then "LWin" else "LCtrl"

local cfg = UI.Schema({
  hotkey = UI.Keybind("F8", { label = "Send selection" }),
  app = UI.Select("Codex", { "Codex", "Claude", "ChatGPT" }, { label = "Send to" }),
  prefix = UI.Text("Here is what I am looking at:", { label = "Starts with" }),
  launch = UI.Text("", {
    label = "Launch command if the app is closed (Windows)",
    placeholder = "full path to the app",
  }),
})

local function copySelection()
  Clipboard.Set("")
  HID.Combo(MOD .. "+C")
  for _ = 1, 10 do
    Sleep(50)
    local text = Clipboard.Get()
    if text and text ~= "" then
      return text
    end
  end
  return nil
end

local function waitFront(app)
  for _ = 1, 30 do
    if App.IsFront(app) then
      return true
    end
    Sleep(100)
    pcall(App.Activate, app)
  end
  return false
end

local function focus(app)
  if pcall(App.Activate, app) and waitFront(app) then
    return true
  end
  if IS_MAC then
    return false
  end
  -- Windows focuses only running apps: start it, then keep asking
  local ok = if cfg.launch ~= ""
    then pcall(System.ExecDetached, cfg.launch, {})
    else pcall(System.ExecDetached, "cmd", { "/c", "start", "", app })
  if not ok then
    return false
  end
  return waitFront(app)
end

Bind(
  cfg.hotkey,
  Async(function()
    local text = copySelection()
    if not text then
      UI.Notify("Nothing selected", "warning")
      return
    end
    Clipboard.Set(cfg.prefix .. "\n\n" .. text)
    if not focus(cfg.app) then
      UI.Notify(`Could not open {cfg.app}. Your text is on the clipboard.`, "warning")
      return
    end
    Sleep(400)
    HID.Combo(MOD .. "+V")
  end)
)

3 files, 3.7 KB.