// Name: Copy Active Window Path // Description: Copies the path of the active window to the clipboard; special handling for Finder windows. // Author: dallascrilley // GitHub: dallascrilley import "@johnlindquist/kit" const info = await getActiveAppInfo().catch(() => null) let pathToCopy = "" if (info?.bundleIdentifier === "com.apple.finder") { // 1) Try selected file try { const selectedFile = await getSelectedFile() if (selectedFile) pathToCopy = selectedFile } catch {} // 2) Try selected/open directory if (!pathToCopy) { try { const selectedDir = await getSelectedDir() if (selectedDir) pathToCopy = selectedDir } catch {} } // 3) Fallback to front Finder window's target via AppleScript if (!pathToCopy) { try { const frontPath = await applescript(` tell application "Finder" if (count of windows) is 0 then return POSIX path of (path to desktop folder) else return POSIX path of (target of front window as alias) end if end tell `) if (frontPath) pathToCopy = frontPath.trim() } catch {} } } else if (info) { // Non-Finder apps: copy executable path, else bundle path pathToCopy = (info.executableURLPath || info.bundleURLPath || "").trim() } if (pathToCopy) { await copy(pathToCopy) await toast(`Copied: ${pathToCopy}`) } else { await toast("No path found for the active window") }