app.finder - Finder Operations API
Interact with macOS Finder.
Return values:
trueon success;falseand an error on failure (the path doesn’t exist, the app can’t be found, or it couldn’t be opened). Versions before iRightMenu Pro 2.7.1 always returntruewithout guaranteeing success.Permission: L1 Standard — must be declared in
permissions("finder")
Methods
app.finder.open(path)
Open a file or directory with the default application.
Parameters:
path(string) - File or directory path
Returns: boolean, error - true on success; false and an error if the path doesn’t exist or couldn’t be opened
-- Open a file
app.finder.open("/path/to/document.pdf")
-- Open a directory
app.finder.open("/path/to/folder")
app.finder.openWith(path, appName)
Open a file with a specified application.
Parameters:
path(string) - File pathappName(string) - Application name
Returns: boolean, error - true on success; false and an error if the file doesn’t exist or the app can’t be found
app.finder.openWith("/path/to/file.txt", "Visual Studio Code")
app.finder.openWith("/path/to/file.txt", "Sublime Text")
app.finder.select(path)
Select a file in Finder (opens the containing directory and selects the file).
Parameters:
path(string) - File path
Returns: boolean, error - true on success; false and an error if the file doesn’t exist
app.finder.select("/path/to/file.txt")
app.finder.reveal(path)
Same as select - reveal a file in Finder.
Parameters:
path(string) - File path
Returns: boolean, error - true on success; false and an error if the file doesn’t exist
app.finder.reveal("/path/to/file.txt")
Examples
Reveal File After Processing
function MyPlugin:handleConvert(context)
for _, file in ipairs(context.selectedFiles) do
local outputPath = app.path.withExtension(file, "png")
if app.image.convert(file, outputPath) then
-- Conversion successful, reveal in Finder
local ok, err = app.finder.reveal(outputPath)
if not ok then
app.log.warning("Couldn't reveal in Finder: " .. err.message)
end
end
end
end
Open with a Specific Application
function MyPlugin:handleOpenWithEditor(context)
for _, file in ipairs(context.selectedFiles) do
app.finder.openWith(file, "Visual Studio Code")
end
end