Coder Social home page Coder Social logo

raycast-toolkit's Introduction

Raycast Toolkit

This is an unofficial package to develop Raycast Extensions that provides additional hooks and components useful to perform more advanced operations.

Documentation

Note: the exported namespaces are suffixed with a dollar sign ($) to avoid to conflict with the @raycast/api ones.

Components

Action$.SelectFile

When this action is called, a Finder file prompt window will be displayed, the user can select the file they prefer and the onSelect callback will be called with the POSIX path of the chosen file.

import { ActionPanel } from '@raycast/api';
import { Action$ } from 'raycast-toolkit';

const Example = () => (
  <ActionPanel>
    <Action$.SelectFile
      prompt="Select a .csv file"
      type="csv"
      onSelect={(path) => console.log('Selected file at path:', path)}
    />
  </ActionPanel>
);

Hooks

usePersistentState

Provides an interface compatible with useState but that persists its value on the Raycast LocalStorage.

import { usePersistentState } from 'raycast-toolkit';

const [persistentCounter, setPersistentCounter] = usePersistentState(
  'my-state-key', // LocalStorage key
  0 // initial value
);

raycast-toolkit's People

Contributors

fezvrasta avatar mathieudutour avatar rishimohan avatar sxn avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

raycast-toolkit's Issues

Handling error/cancel in Action$.SelectFile

@FezVrasta First of all thanks for publishing this. I realized when Cancel is triggered while opening a file through Action$.SelectFile, it throws error. There seems no way to handle this error, even with try catch. It would be great if there can be a callback to handle errors.

Steps to reproduce:

  • Try opening a file
  • Close the file picker without selecting a file

Here's the screenshot of the error:

image

Here's the log:

Error: Command failed with exit code 1: osascript -e 
      set chosenFile to choose file with prompt "Please select an image:"of type {"public.image"}
      set raycastPath to POSIX path of (path to application "Raycast")
      do shell script "open " & raycastPath
      return POSIX path of chosenFile
    
25:98: execution error: User cancelled. (-128)

                error = new Error(message);
                        ^
Error: Command failed with exit code 1: osascript -e 
      set chosenFile to choose file with prompt "Please select an image:"of type {"public.image"}
      set raycastPath to POSIX path of (path to application "Raycast")
      do shell script "open " & raycastPath
      return POSIX path of chosenFile
    
makeError:error.js:60:11

---
57:             error.originalMessage = error.message;
58:             error.message = message;
59:     } else {
60:             error = new Error(message);
61:     }
62: 
63:     error.shortMessage = shortMessage;
---

handlePromise:index.js:118:26
runAppleScript:index.js:9:19
<anonymous>:Action.mjs:7:22
21:40:13.187 
Error: Command failed with exit code 1: osascript -e 
      set chosenFile to choose file with prompt "Please select an image:"of type {"public.image"}
      set raycastPath to POSIX path of (path to application "Raycast")
      do shell script "open " & raycastPath
      return POSIX path of chosenFile
    
25:98: execution error: User cancelled. (-128)

                error = new Error(message);
                        ^
Error: Command failed with exit code 1: osascript -e 
      set chosenFile to choose file with prompt "Please select an image:"of type {"public.image"}
      set raycastPath to POSIX path of (path to application "Raycast")
      do shell script "open " & raycastPath
      return POSIX path of chosenFile
    
makeError:error.js:60:11

---
57:             error.originalMessage = error.message;
58:             error.message = message;
59:     } else {
60:             error = new Error(message);
61:     }
62: 
63:     error.shortMessage = shortMessage;
---

handlePromise:index.js:118:26
runAppleScript:index.js:9:19
<anonymous>:Action.mjs:7:22

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.