QuickLook

The QuickLook API in the Scripting app provides a simple way to preview text, images, or files within your scripts. This is a wrapper around iOS QuickLook capabilities, allowing you to quickly display previews for a wide range of content types.

Each method returns a promise that resolves when the QuickLook view is dismissed, enabling you to chain actions or handle post-preview logic easily.


API Reference

QuickLook.previewText(text: string): Promise<void>

Displays a preview of a text string.

Parameters

  • text (string): The text content to display in the preview.
  • fullscreen (boolean?): Whether preview in a fullscreen mode. Defaults to false.

Returns

  • A Promise<void>: Resolves after the preview is dismissed.

Example

1await QuickLook.previewText("Hello, world! This is a QuickLook preview.")
2console.log("Text preview dismissed")

QuickLook.previewImage(image: UIImage): Promise<void>

Displays a preview of an image.

Parameters

  • image (UIImage): The image to display in the preview.
  • fullscreen (boolean?): Whether preview in a fullscreen mode. Defaults to false.

Returns

  • A Promise<void>: Resolves after the preview is dismissed.

Example

1// Assume `myImage` is a UIImage instance
2await QuickLook.previewImage(myImage)
3console.log("Image preview dismissed")

QuickLook.previewURLs(urls: string[]): Promise<void>

Displays a preview of one or more files located at the given file URL strings.

Parameters

  • urls (string[]): An array of file URL strings. Each string should point to a valid file path or remote file that can be previewed by QuickLook.
  • fullscreen (boolean?): Whether preview in a fullscreen mode. Defaults to false.

Returns

  • A Promise<void>: Resolves after the preview is dismissed.

Example

1const fileURLs = [
2  "/path/to/file1.pdf",
3  "/path/to/file2.jpg",
4]
5
6await QuickLook.previewURLs(fileURLs)
7console.log("File previews dismissed")

Usage Notes

  • UI Blocking: These methods present a modal QuickLook view. Execution of subsequent code (after await) will pause until the user dismisses the preview.
  • Error Handling: Use try...catch to handle errors such as invalid file paths or unsupported content types.
  • Supported File Types: The supported file types depend on iOS QuickLook capabilities, which include common file types like PDFs, images, text files, and more.

Example Use Case

Previewing Text, Images, and Files Sequentially

1// Preview a text
2await QuickLook.previewText("QuickLook Preview Example")
3
4// Preview an image
5const myImage = UIImage.fromFile("/path/to/image.png")
6await QuickLook.previewImage(myImage)
7
8// Preview files
9const fileURLs = [
10  "/path/to/file1.pdf",
11  "/path/to/file2.jpg",
12]
13await QuickLook.previewURLs(fileURLs)
14
15console.log("All previews completed")

With this API, you can integrate QuickLook previews seamlessly into your scripts, enhancing the user experience with minimal effort.