app.finder - Finder Operations API
Interact with macOS Finder.
Note: All Finder operations are executed asynchronously and return
trueimmediately without guaranteeing the operation succeeded.
Methods
app.finder.open(path)
Open a file or directory with the default application.
Parameters:
path(string) - File or directory path
Returns: boolean - Always returns true (executed asynchronously)
-- 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 - Always returns true (executed asynchronously)
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 - Always returns true (executed asynchronously)
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 - Always returns true (executed asynchronously)
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.removeExtension(file) .. ".png"
if app.image.convert(file, outputPath) then
-- Conversion successful, reveal in Finder
app.finder.reveal(outputPath)
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