Utility

Utility

The Utility protocol:

protocol Utility {
  func openURL(_ string: String)
 
  func viewInOKJSON(_ string: String)
 
  func copyString(_ string: String)
 
  func getClipboardText() -> String
 
  func paste()
}

$utility.openURL

$utility.openURL('https://okjson.app');

Open URL with default configuration. The URL can be an HTTP link or a URL Scheme.

$utility.openInOKJSON

let string = `
{"hello": "world"}
`;
$utility.viewInOKJSON(string);

View JSON string in OK JSON.

$utility.copyString

$utility.copyString('OK JSON');

Copy string to clipboard.

$utility.getClipboardText

let text = $utility.getClipboardText();

Get text from clipboard.

If your clipboard contains a path to a text file, $utility.getClipboardText will read the file and return the file content instead.

$utility.paste

$utility.copyString('OK JSON');
$utility.paste();

Paste the clipboard content to the frontmost app.

Only works when OK JSON is not frontmost. For example, when run script from the Raycast extension.

You can combine $utility.paste with $file.copy to paste the result file in Finder.

let path = '/markdown/hello-world.md';
$file.copy(path);
$utility.paste();
💡

For $utility.paste to work, Accessibility permission is required for OK JSON.

To permit, go to System SettingsPrivacy & SecurityAccessibility or click here.