Background SwiftBiu API
Standard Actions and Web App launchers run in the background script.js sandbox. This environment injects the global SwiftBiu object and its lowercase alias swiftBiu.
Important
This page applies only to background script.js. Web pages use the asynchronous window.swiftBiu bridge described in Web UI API.
Environment and Configuration
SwiftBiu.isSandboxed:Boolean, whether the app is running inside macOS App Sandbox.SwiftBiu.getConfig(key: String): synchronously reads a configuration value as a string.SwiftBiu.setConfig(key: String, value: String): persists a configuration value.SwiftBiu.screenSize: helps calculate initial Web UI size and position.
Clipboard and Text
SwiftBiu.writeToClipboard(text: String): writes text to the system clipboard. RequiresclipboardWrite.SwiftBiu.copyText(text: String): compatible copy helper.SwiftBiu.getClipboard(): returns plain text from the clipboard. RequiresclipboardRead.SwiftBiu.pasteText(text: String): copies and pastes into the previously active window. Requirespaste.
Local File Reads and Metadata
SwiftBiu.getFileMetadata(path: String): returns size, timestamps, and content type. RequireslocalFileRead.SwiftBiu.readLocalFile(path: String): reads a selected file and returns Base64. RequireslocalFileRead.SwiftBiu.readLocalTextFile(path: String): decodes a selected file as UTF-8. RequireslocalFileRead.SwiftBiu.listDirectory(path: String): lists direct children and metadata. RequireslocalFileRead.SwiftBiu.fileExists(path: String): checks whether a path exists as a file. RequireslocalFileReadorlocalFileWrite.SwiftBiu.directoryExists(path: String): checks whether a path exists as a directory. RequireslocalFileReadorlocalFileWrite.
File and Folder Authorization
SwiftBiu.pickLocalFile(options?: Object): opens the native file picker, persists authorization, and returns the selected path. Supportskind: "application",kind: "image", andallowedExtensions. RequireslocalFileReadorlocalFileWrite.SwiftBiu.pickLocalDirectory(): opens the native folder picker, persists authorization, and returns the folder path. RequireslocalFileWrite.SwiftBiu.requestDirectoryAuthorization(path: String): asks the user to authorize a folder covering the target path. RequireslocalFileWrite.SwiftBiu.hasAuthorizedDirectoryAccess(path: String): checks whether persisted authorization covers a path. RequireslocalFileWrite.
When access is missing, request authorization immediately. Stop cleanly when the user cancels instead of returning a false success state.
Local File Writes
SwiftBiu.createLocalDirectory(path: String): creates a directory in an authorized location. RequireslocalFileWrite.SwiftBiu.createLocalFile(path: String, base64String: String): creates a file from Base64. RequireslocalFileWrite.SwiftBiu.writeLocalTextFile(path: String, text: String): creates a UTF-8 text file. RequireslocalFileWrite.SwiftBiu.overwriteLocalFile(path: String, base64String: String): replaces an accessible file. RequireslocalFileWrite.SwiftBiu.renameLocalFile(path: String, newName: String): renames a file in place. RequireslocalFileWrite.SwiftBiu.copyLocalFile(sourcePath: String, destinationPath: String): copies a file. RequireslocalFileWrite.SwiftBiu.moveLocalFile(sourcePath: String, destinationPath: String): moves a file. RequireslocalFileWrite.SwiftBiu.trashLocalItem(path: String): moves an item to the macOS Trash. RequireslocalFileWrite.
File Icons
SwiftBiu.extractFileIcon(path: String, options?: Object): extracts a file or app icon through the native host. Success returns{ success, base64, fileName, width, height, format }; failure returns{ success: false, error }. RequireslocalFileRead.SwiftBiu.setFileIcon(targetPath: String, iconPath: String, options?: Object): applies a custom Finder icon to a file, folder, or.app. RequireslocalFileReadandlocalFileWrite.
For App Store compatibility, use these host APIs instead of shell, AppleScript, sips, qlmanage, or osascript.
Opening Resources
SwiftBiu.openURL(urlString: String): opens a link in the default browser.SwiftBiu.openFileInPreview(filePath: String): opens a file in the default macOS app.SwiftBiu.openFileWithApp(filePath: String, appBundleID: String): opens a file with a specific app and returnsBoolean. RequireslocalFileRead.
Notifications, Images, and Loading
SwiftBiu.showNotification(title: String, body: String): sends a system notification. Requiresnotifications.SwiftBiu.showImage(imageSource: String, position?: Object, context?: Object): displays a native image toast from Base64 or anhttp/httpsURL. Requiresnotifications.SwiftBiu.showInteractiveImage(options, onRegenerate): creates an interactive image session and returnssessionID. Requiresnotifications.SwiftBiu.updateInteractiveImage(sessionID, options): updates an image session.SwiftBiu.failInteractiveImage(sessionID, message): fails an image session.SwiftBiu.showLoadingIndicator(position: Object): shows a native loading indicator.SwiftBiu.hideLoadingIndicator(): hides it.
Use the loading indicator only for lightweight actions without their own interface. Web UIs, AI bubbles, and image sessions should manage loading inside their own lifecycle.
Network Requests
SwiftBiu.fetch(url, options, onSuccess, onError): callback-based request. Requiresnetwork.SwiftBiu.fetchStream(url, options, onEvent, onError): starts a stream and returnsstreamID. Requiresnetwork.SwiftBiu.cancelFetchStream(streamID: String): cancels an active stream.
Shell Scripts
SwiftBiu.runShellScript(script, context): synchronously executes Bash or Zsh. RequiresrunShellScript.
Warning
App Store sandboxing can block subprocesses and file-system access. Cross-platform and App Store-compatible plugins should not depend on shell execution as their primary implementation.