FileBrowser is mini File System browser for Scriptable which can be used to:
- browse the local file system1
- browse iCloud folders1
- browse bookmarked folders.
FileBrowser can be also used as a file picker for local directories.
1Files and folders accessible through the sandbox. Jailbroken devices will be able to browse the whole file system.
Example Usage:
const {FileBrowser} = importModule('file-browser')
const path = FileManager.local().documentsDirectory()
const browser = new FileBrowser(path)
const file = await browser.present()Download
DOWNLOAD using Import-Script or copy the code from file-browser.js and save in Scriptable.
Construct a new FileBrowser.
new FileBrowser(path, options)path : the directory to browse
options : a JSON value indicating the additional options to change the behaviour of the browser
canBrowseParent: Boolean: allow browsing above the initial path. Useful for exploring outside the known directories. Default false.precheckAccess: Boolean: while listing directory contents, check each sub-directory is accessible or not. Inaccessible directories will be colored in red. Default true.fullscreen: Boolean: open the file browser in fullscreen. Default true.
A static method with the same parametes as the constructor. This allows the caller to open the file browser by simply calling FileBrowser.browse(). If the path parameter is null, a list of predefined locations to choose from will be presented. Use this to explore the file system or just run the script itself.
browse(): Promise<FileInfo>Launches the file browser returns a JSON value containing information about the selected file.
In version 1.1 a pickFile alias was introduced because technically, FileBrowser is a file picker. So, so it makes more sense to say FileBrowser.picFile().
present(): Promise<FileInfo>Deprecated. use FileBrowser.view() instead. Will be obsoleted on the next major version.
opens a QuickLook on the file. path is the path to the file. FileBrowser will try to auto-detect images and present the image itself. Any other file will be treated as a text file. If it is unable to read the file contents, it will show <eof>.
previewFile(path:String)Presents a list of built-in directories that Scriptable has access to. Choosing any of them will return the path to that directory.
pickScriptableDirectory(): StringOpens a QuickLook on the file. path is the path to the file. FileBrowser will try to auto-detect the file type and present with the suitable viewer. If it is unable to read the file contents, it will show <unable to read contents>.
view(path:String)QuickLook on an image file.
viewImage(path:String)Reads a file as text and presents via Quick Look.
viewText(path:String)Reads a file as text and parses as JSON. It is presented using Quick Look which allowed navigating around the structure.
viewJSON(path:String)Passes the file path to the built-in QuickLook.present().
viewPath(path:String)Reads the file as Data bytes and converts bytes into a string and present via Quick Look.
viewOctet(path:String)Reads the file as Data bytes and converts bytes into a string and present via Quick Look. It accepts a JSON or a class which contains the mimetype and view keys.
addViewer(viewer = {mimetype:String, view:Promise<function(path:String)>})mimetype : the mime type of the file that will be handled by the viewer. Example image/jpeg
view : a function that accepts a path to the file and presents it for viewing.
Allow browsing above the inital path. Useful for exploring outside the known directories.
canBrowseParent: BooleanOpen the file browser in full screen.
fullscreen: BooleanThe initial path to use when the FileBrowser is presented. By default, navigating to the parent directory of this folder is not allowed. Pass the canBrowseParent option to override.
path: StringTest and colorized inaccessible sub-directories.
precheckAccess: BooleanThe current directory being displayed.
pwd: StringAn array of key-value pairs representing the default file viewers
viewers: {}const path = FileManager.bookmarkedPath('Shortcuts')
const browser = new FileBrowser(path)
const file = await browser.present()const {FileBrowser} = importModule('file-browser')
const path = '/Developer'
const browser = new FileBrowser(path)
const file = await browser.present()const {FileBrowser} = importModule('file-browser')
const path = '/Developer'
const browser = new FileBrowser(path, {precheckAccess:false})
const file = await browser.present()A class to identify and provide metadata about a file.
const file = new FileInfo(filePath: String)
/*
metadata sample
{
"isDir" : false,
"type" : "file",
"nameOnDisk": "AccessibilityDefinitions.plist,
"pathOnDisk": "/System/Library/Accessibility/AccessibilityDefinitions.plist",
"parent" : "/System/Library/Accessibility/",
"name" : "AccessibilityDefinitions.plist",
"basename" : "AccessibilityDefinitions",
"path" : "/System/Library/Accessibility/AccessibilityDefinitions.plist",
"size" : 584,
"isOnCloud" : false,
"modified" : "2020-01-01T08:00:00.000Z",
"isImage" : false,
"mimetype" : "application/xml",
"canAccess" : true,
"itemCount" : 0,
"uti" : "com.apple.property-list",
"extension" : "plist",
"isCloudAlias": false
}
*/