|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > HTP. - Command > !HTP-General - General HTTP operations and utilities > !Utility - Helper functions for HTTP operations (string conversion, proxy toggling) > HTP. - HTTP Operations |
SPR Script Language
HTP.WToClip
Copies the last decoded Unicode (WSTRING) result to the system clipboard.
Intention
The HTP.WToClip command provides a reliable way to get complex text, such as text containing emojis or special Unicode characters, out of the script and onto the clipboard. It takes the most recent decoded response from a command like HTP.ReqShort (which is stored internally as a Unicode WSTRING) and places it on the clipboard.
This is the preferred method for copying text that may not be representable in the standard system code page, ensuring perfect fidelity. The command also returns the same content to the top-of-stack as a UTF-8 string for immediate use.
Syntax
HTP.WToClip
Parameter Explanation
This command has no parameters.
Examples
'***********************************
' HTP.WToClip - Sample 1: Copying an AI response with Emojis
'***********************************
VAR.$$URL=https://api.openai.com/v1/chat/completions
VAR.$$KEY=sk-YourSecretKeyHere
VAR.$$DAT={"model":"gpt-4o","messages":[{"role":"user","content":"Respond with: Hello World! 😊👍"}]}
' Make the request. The decoded WSTRING response is stored internally.
HTP.ReqShort|POST|$$URL|$$DAT|$$KEY|$$RES
JIV.$$TOS!200|Lab_failed
' Extract the content from the JSON response
PSJ.ExtractChoicesContent|$$RES|$$VAL
' At this point, the last WSTRING result is the full JSON from HTP.ReqShort.
' To copy just the extracted text, we need to get it into the internal buffer.
' We can do this with HTP.FromUTF8, which returns the result as a WSTRING.
HTP.FromUTF8|$$VAL
' Now, copy the extracted content to the clipboard
HTP.WToClip
MBX.Done|The AI response has been copied to the clipboard. Paste it into a text editor to see the emojis.
END.
Remarks
- This command copies the result of the last successful decoding operation, which is typically from HTP.ReqShort or by using HTP.FromUTF8.
- The command also returns the copied content as a standard UTF-8 string to the top-of-stack ($$TOS) for immediate use in the script.
- To enable/disable automatic clipboard copying for all requests, use HTP.SetClipOutput.
See also:
• HTP.GetW