// Name: Bookmark Browser // Description: Opens selected bookmark in browser // Author: HugoMarx import '@johnlindquist/kit'/** * Interface defining the structure of a bookmark object. */ interface Bookmark { name: string; url: string; } /** * Asynchronously retrieves a list of bookmarks. * * @returns {Promise<Bookmark[]>} A promise that resolves to an array of Bookmark objects. * * @remarks * This function is currently a placeholder and returns dummy data. * In a real application, this function should be implemented to fetch bookmarks * from the user's browser or a bookmark management system. * * Example for macOS (requires parsing specific plist/JSON files): * For Chrome: ~/Library/Application\ Support/Google/Chrome/Default/Bookmarks * For Safari: ~/Library/Safari/Bookmarks.plist */ const getBookmarks = async (): Promise<Bookmark[]> => { // Dummy data for demonstration: return [ { name: 'Script Kit', url: 'https://scriptkit.com' }, { name: 'Google', url: 'https://google.com' }, { name: 'GitHub', url: 'https://github.com' }, ]; }; /** * Fetches bookmarks asynchronously. */ const bookmarks: Bookmark[] = await getBookmarks(); /** * Transforms the bookmarks array into a format suitable for `arg` choices. * Each bookmark is converted to a Choice object with name, value, and description. */ const choices: Choice[] = bookmarks.map((bookmark) => ({ name: bookmark.name, value: bookmark.url, description: bookmark.url, })); /** * Uses `arg` to prompt the user to select a bookmark from the list of choices. * The selected bookmark URL is stored in the `url` variable. */ const url: string = await arg<string>('Select a bookmark', choices); /** * Checks if a URL was selected. * If a URL is selected, it opens the URL in the default browser using the `browse` function. */ if (url) { await browse(url); }