Skip to main content
Glama

finder_get_selection

Retrieve currently selected files and folders in macOS Finder to enable AI agents to access and manage user-selected items for automation tasks.

Instructions

Get currently selected files/folders in Finder

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler for 'finder_get_selection' tool. Executes AppleScript via osascript to get Finder's current selection as alias list, processes stderr for errors, handles empty selection, parses aliases into friendly file/directory names (handling directories and .localized), and returns formatted list of selected items.
    case 'finder_get_selection': try { const command = `osascript -e 'tell application "Finder" to get selection as alias list'`; const { stdout, stderr } = await execAsync(command); if (stderr.trim()) { return { content: [ { type: 'text', text: `Error getting Finder selection: ${stderr.trim()}`, }, ], }; } const output = stdout.trim(); if (!output || output === '') { return { content: [ { type: 'text', text: 'No files selected in Finder', }, ], }; } // Process AppleScript aliases to user-friendly names const aliases = output.split(', '); const friendlyNames = aliases.map(alias => { // Extract filename from alias path const pathParts = alias.replace('alias ', '').split(':'); // Check if it's a directory (ends with colon, creates empty last element) const isDirectory = alias.endsWith(':'); let filename; if (isDirectory) { // For directories: take second-to-last element (last is empty from trailing colon) filename = pathParts[pathParts.length - 2]; } else { // For files: take last element filename = pathParts[pathParts.length - 1]; } // Remove .localized suffix if present if (filename && filename.endsWith('.localized')) { filename = filename.replace('.localized', ''); } return isDirectory ? `${filename}/` : filename; }); return { content: [ { type: 'text', text: `Selected items (${friendlyNames.length}):\n${friendlyNames.join('\n')}`, }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `Error executing Finder selection command: ${error.message}`, }, ], }; }
  • src/index.ts:52-59 (registration)
    Tool registration in ListToolsRequestSchema handler, defines name, description, and empty inputSchema (no parameters required).
    { name: 'finder_get_selection', description: 'Get currently selected files/folders in Finder', inputSchema: { type: 'object', properties: {}, }, },
  • Input schema for finder_get_selection: empty object (no input parameters).
    inputSchema: { type: 'object', properties: {}, },
  • Test invocation of finder_get_selection tool, notes it requires manual Finder selection.
    // finder_get_selection requires manual selection, skipping or expecting empty await testTool('finder_get_selection');

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/samicokar/mcp-mac'

If you have feedback or need assistance with the MCP directory API, please join our Discord server