Skip to content

ferraridavide/ChatGPTPowerToys

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

ChatGPT for PowerToys Run

logo

How to install

If you simply want to install the plugin to get up and running quickly, i suggest downloading the precompiled binaries from the Release section and installing the Tampermonkey user script The installation process is as follows:

  1. Locate your PowerToys installation (eg. C:\Program Files\PowerToys)
  2. Navigate to \modules\launcher\Plugins
  3. Unpack the downloaded binaries

Compiling plugin

  1. Clone the PowerToys repository to your local disk using the command git clone https://github.com/microsoft/PowerToys.git
  2. Navigate to the PowerToys directory using cd PowerToys
  3. Initialize and update submodules with the command git submodule update --init --recursive
  4. Fork the ChatGPTPowerToys repository on GitHub
  5. Clone the fork of ChatGPTPowerToys into the local PowerToys repository by running git clone https://github.com/ferraridavide/ChatGPTPowerToys.git in the PowerToys\src\modules\launcher\Plugins directory
  6. In Visual Studio, add the local clone of ChatGPTPowerToys as an existing project to the PowerToys's Plugins folder (modules\launcher\Plugins)
  7. Compile

Unfortunately, ChatGPT does not provide a query string parameter for passing prompts. Therefore, we must utilize a browser extension to inject the prompt.

Using Tampermonkey (recommended)

Tampermonkey is a popular browser extension that allows to inject custom user scripts in webpages, visit tampermonkey.net to install it.

Install this script

// ==UserScript==
// @name         PowerToys Run ChatGPT Helper
// @version      0.3
// @description  https://github.com/ferraridavide/ChatGPTPowerToys
// @author       Davide Ferrari
// @match        https://chat.openai.com/?PTquery=*
// @icon         https://raw.githubusercontent.com/ferraridavide/ChatGPTPowerToys/master/src/PowerToys.ChatGPT.BrowserExtension/icons/icon128.png
// @grant        none
// ==/UserScript==
(function() {
    'use strict';
    console.log("PowerToys Run ChatGPT Helper script loaded");
    const searchParams = new URLSearchParams(window.location.search);
    const prompt = searchParams.get("PTquery");
    if (prompt) {
        setTimeout(() => {
            const textArea = document.querySelector("form textarea");
            if (!textArea) {
                console.error("Cannot find the textarea element");
                return;
            }
            textArea.value = prompt;
            const inputEvent = new Event('input', {
                'bubbles': true,
                'cancelable': true
            });
            textArea.dispatchEvent(inputEvent);

            setTimeout(() => {
                const submitButton = document.querySelector("form button");
                if (!submitButton) {
                    console.error("Cannot find the submit button");
                    return;
                }
                submitButton.click();
            }, 500);
        }, 1000);
    }
})();
AIPRM browser extension compatability Thanks to @babico for providing this modified script!
// ==UserScript==
// @name         PowerToys Run ChatGPT Helper
// @version      0.2
// @description  https://github.com/ferraridavide/ChatGPTPowerToys
// @author       Davide Ferrari
// @match        https://chat.openai.com/?PTquery=*
// @icon         https://raw.githubusercontent.com/ferraridavide/ChatGPTPowerToys/master/src/PowerToys.ChatGPT.BrowserExtension/icons/icon128.png
// @grant        none
// ==/UserScript==

(function() {
   'use strict';

   console.log("PowerToys Run ChatGPT Helper script loaded");

   const searchParams = new URLSearchParams(window.location.search);
   const prompt = searchParams.get("PTquery");

   if (prompt) {
       setTimeout(() => {
           const textArea = document.querySelector("form textarea");
           const submitButton = document.querySelectorAll("form button")[1]; // AIPRM add another button so change with the second button

           if (!textArea || !submitButton) {
               console.error("Cannot find required elements");
           }

           textArea.value = prompt;
           submitButton.disabled = false;
           submitButton.click();
       }, 500);
   }
})();

Using the custom browser extension

  1. Open your preferred browser and navigate to the settings or preferences menu.
  2. Locate the option for "extensions" or "add-ons" and select it.
  3. Enable developer mode in the extensions settings page.
  4. In the extensions menu, look for a button or option labeled "Load Unpacked" or "Add Unpacked Extension."
  5. Select the folder containing the extension and click "Open."