Skip to content

Add script to open Claude and submit prompt #954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 30, 2024
Merged

Conversation

nimobeeren
Copy link
Contributor

@nimobeeren nimobeeren commented Aug 7, 2024

Description

This script opens Claude in Chrome browser and submits the prompt provided as argument.

Type of change

New script command

Screenshot

claude-alt-space.mp4

Dependencies / Requirements

This script requires the following software to be installed:

Install via homebrew: brew install node chrome-cli

This script needs to run JavaScript in your browser, which requires your permission. To do so, open Chrome and find the menu bar item: View > Developer > Allow JavaScript from Apple Events

Checklist

Copy link
Contributor

@unnamedd unnamedd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nimobeeren, thanks for you first contribution to our repository,

I've made some small comments on your PR, give a check and re-request a review when you finish to address them.

#!/usr/bin/env node

// Dependency: This script requires `chrome-cli` installed: https://github.com/prasmussen/chrome-cli
// Install via homebrew: `brew install chrome-cli`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be better if you note here that node is another requirement, since node isn't something pre-installed on macOS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

execSync("which chrome-cli");
} catch {
console.error(
"chrome-cli is required to run this script (https://github.com/prasmussen/chrome-cli)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means your Script Command will only work on Chrome, maybe you should open the usage of your Script Command to users of other browsers, even though, many of them uses Chromium as engine, sounds to me that chrome-cli will work only for Chrome.

Is something that important to be able to search for an open Claude tab in the browser to reuse it with a new prompt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chrome-cli indeed works with other Chromium-based browsers through aliases such as brave-cli (see the chrome-cli readme). However, I'm not sure how to detect which browser the user would prefer. The most straight-forward approach I see is letting the user modify this script if they want to use another browser.

I could add a variable at the top of the script to make it easier to change the chrome-cli executable. What do you think is best?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you're asking whether the chrome-cli dependency is necessary at all, the main reason I need it is to be able to run my JavaScript in the browser. Though I just found out that it might be possible to do this with AppleScript too, so that could eliminate the need for this dependency. I'm not able to rewrite the script in AppleScript at the moment though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could add a variable at the top of the script to make it easier to change the chrome-cli executable. What do you think is best?

Maybe in this case, you could make the extension a template (just adding .template in the file name and tell the user to uncomment the line related to its browser: brave, chrome and so on. What do you think?

@nimobeeren
Copy link
Contributor Author

@unnamedd thanks for your review! I've implemented or replied to your comments.

I've also changed behavior to open in a new tab instead of new window, and added a note to tell the user to enable JavaScript from Apple Events. Could you give it another look?

@nimobeeren nimobeeren requested a review from unnamedd August 16, 2024 18:24
Copy link
Contributor

@unnamedd unnamedd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nimobeeren,

thanks for you contribution! Even though there are something we could improve here, it looks good to me!

If you prefer to make improvements later, will be a pleasure to review them later!

@unnamedd unnamedd added the accepted PR is ready to be merged label Aug 19, 2024
@unnamedd
Copy link
Contributor

@nimobeeren I found this link earlier today (Claude’s API now supports CORS requests, enabling client-side applications). Perhaps it might be interesting to you.

@nimobeeren
Copy link
Contributor Author

@nimobeeren I found this link earlier today (Claude’s API now supports CORS requests, enabling client-side applications). Perhaps it might be interesting to you.

Thanks, that's good to know! I think this only applies to the API though, rather than the user-facing Claude product. I think there is a place for API-based interactions with LMMs (like Raycast AI), but this script is meant to work with the (free or paid) web interface.

@adilrc adilrc merged commit 803776e into raycast:master Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted PR is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants