app.context - Context API

Access Finder selection context and plugin directory information.

Not the same thing as the context argument your menu handler receives.

> function MyPlugin:handleAction(context)
>     local files = context.selectedFiles       -- property, snapshot of this click
>     local files = app.context.selectedFiles() -- function, queried right now
> end
> ```
>
> - **The handler's `context` argument** is a snapshot taken **when the menu was clicked**,
>   with just `selectedFiles` and `currentDirectory`. Prefer it inside handlers — it is
>   guaranteed to match what the user had selected.
> - **The `app.context.*` global API** queries live, at call time. Use it outside handlers:
>   in `getMenuTitle`, in background timers, in coroutines — places where no `context`
>   argument exists.
>
> During a long-running task the user may change the selection, and the two will disagree.
> If you want "what was selected when they clicked", use the argument.

> **Permission**: L0 Safe — always available, no declaration needed

## Methods

### app.context.selectedFiles()

Gets the file paths selected in Finder.

**Returns**: `table` - Array of absolute paths

```lua
local files = app.context.selectedFiles()
for _, path in ipairs(files) do
    app.log.info(path)
end

app.context.currentDirectory()

Gets the directory of the current Finder window.

Returns: string - Directory path

local dir = app.context.currentDirectory()
-- "/Users/username/Documents"

app.context.pluginsDirectory()

Gets the plugin installation directory.

Returns: string - Directory path

local dir = app.context.pluginsDirectory()
-- "~/Library/Group Containers/group.net.ymlab.iRightMenu.pro/Plugins"

app.context.pluginDirectory()

Gets the current plugin’s directory.

Returns: string - Directory path

local dir = app.context.pluginDirectory()
-- "~/Library/Group Containers/.../Plugins/com.example.my-plugin"

-- Read a plugin resource file
local configPath = app.path.join(dir, "config.json")

Examples

Processing selected files

function MyPlugin:handleAction(context)
    local files = app.context.selectedFiles()
    local dir = app.context.currentDirectory()

    app.log.info("Current directory: " .. dir)
    app.log.info("Selected files: " .. #files)

    for i, file in ipairs(files) do
        app.log.info("File " .. i .. ": " .. file)
    end
end

Reading plugin configuration

function MyPlugin:loadConfig()
    local pluginDir = app.context.pluginDirectory()
    local configPath = app.path.join(pluginDir, "config.json")

    if app.file.exists(configPath) then
        local content = app.file.read(configPath)
        return app.json.parse(content)
    end
    return {}
end
Developer Documentation
User Guide
Getting Started Menu Editor Guide Plugin Manager Settings Script Menus FAQ
Script Development
Development Guide
Plugin Development
Quick Start Development Guide Example Plugins
API Reference
Overview API Query Plugin Info Logging Finder Context Plugin Settings Internationalization
UI & Interaction
Dialog Progress Notification Chooser WebView Status Bar Dock
Files & Paths
File Operations Path Utilities Finder Actions Trash Extended Attributes Metadata File Watcher
Data Formats
JSON Plist CSV XML PDF Image
Text & Encoding
String Regex Date & Time Color Crypto
System
Shell Commands Process Application System Info AppleScript Shortcuts
System Info
Network Power/Battery Screen/Appearance Audio Bluetooth Location
Network
HTTP WebSocket URL
Input & Clipboard
Keyboard Mouse Hotkey Clipboard Window
Storage
SQLite Keychain UserDefaults
Media
OCR QR Code
Utilities
Archive UTI Share Timer Wake Lock Thread