Universal file selection getter for Raycast extensions
npm install universal-selectionA universal file selection getter for Raycast extensions. Automatically detects the frontmost file manager application and retrieves selected files.
- Support for multiple file managers
- Easy integration with Raycast extensions
- Compatible with Raycast's getSelectedFinderItems API
``bash`
npm install universal-selection
`javascript
import { getSelectedItems } from "universal-selection";
import { showToast, Toast } from "@raycast/api";
export default async function Command() {
try {
const files = await getSelectedItems();
if (files.length === 0) {
await showToast({
style: Toast.Style.Failure,
title: "No files selected",
});
return;
}
// Process your files - same format as getSelectedFinderItems
console.log("Selected files:", files);
// [{ path: "/Users/username/Documents/file.txt" }, { path: "/Users/username/Pictures/image.png" }]
files.forEach(file => {
console.log(Processing: ${file.path});`
});
} catch (error) {
await showToast({
style: Toast.Style.Failure,
title: "Error",
message: error.message,
});
}
}
Returns a promise that resolves to an array of file system items.
Returns: Promise
Throws:
- Error - If the frontmost application bundle ID cannot be determinedError
- - If the frontmost application is not supported
Example:
`javascript
const files = await getSelectedItems();
// [{ path: "/path/to/file1.txt" }, { path: "/path/to/file2.png" }]
// Access file paths
files.forEach(file => console.log(file.path));
`
| Application | Bundle ID | Status |
|------------|-----------|--------|
| Finder | com.apple.finder | ✅ Supported |com.asiafu.Bloom
| Bloom | | ✅ Supported |com.jinghaoshe.qspace(.pro)
| QSpace | | ✅ Supported |com.cocoatech.PathFinder
| Path Finder | | ✅ Supported |
Want to add support for more file managers? Open an issue or submit a pull request!
1. Create a new file in src/apps/ (e.g., my-app.js)src/index.js
2. Implement the selection getter function
3. Add the bundle ID case in
4. Update the README
Example:
`javascript
// src/apps/my-app.js
import { runAppleScript } from "@raycast/utils";
export async function getMyAppSelection() {
const script =
tell application "MyApp"
-- Your AppleScript here
end tell
;``
const result = await runAppleScript(script);
return result.trim().split("\n");
}
MIT
Contributions are welcome! Please feel free to submit a Pull Request.