The OSAxFinderLib Swift package provides both a library and a command line tool for fetching the URLs of the currently selected items in the macOS Finder.
Motivation: The current macOS Swift APIs (e.g. FileManager and NSWorkspace) do not provide access to the currently selected Finder URLs.
final class OSAxFinderInitializers
-
init(arguments: [String])Supports library use by a command line tool
Command Line Tool Support
-
func run() throwsSupports library use by a command line tool
Instance Methods
Enclosing Directory
-
func dirOfFirstSelectedFile() -> URL?Fetch the URL of the first selected file
-
func dirOfFrontWindow() -> URL?Fetch the URL of the front Finder window. Returns nil if no window is open.
General Selections
-
func selectedFileUrls(extensions: [String]) -> [URL]Fetch the URL of the selected files and folders which have one of the specified extensions. The extensions are provide without a . dot. For example: ["jpg", "png"]
-
func selectedFolderUrls(suffixes: [String], withAliasToDir: Bool, onlyValid: Bool) -> [URL] -
func selectedUrls(endings: [String]) -> (dirs: [URL], files: [URL])Fetch the URL of the selected files and folders which have one of the specified extensions. The extensions are provide without a . dot. For example:
["jpg", "png"] -
func selectedUrls() -> [URL]
Specialized Selections
func selectedHtml() -> [URL]func selectedImages() -> [URL]func selectedMarkdown() -> [URL]func selectedPdf() -> [URL]func selectedPdfSorted() -> [URL]
Workflow Methods
-
func selectedItemsJson(printStdio: Bool = false) -> Data?- Step 1. Fetch all selected items in JSON format
- Returns: all selected items
-
func selectedItemsList() -> [OSAxFinderItem]- Step 2. All selected items as
OSAxFinderItem
- Step 2. All selected items as
-
func selectedItemsUrls( files: Bool, folders: Bool, aliases: Bool = false, links: Bool = false, validOnly: Bool = true ) -> [URL]- Step 3. Selected and filtered URL array.
See man pages for more information on osascript, osacompile, osalang.