Last active
November 19, 2025 15:04
-
-
Save qianlifeng/82a2f748177ce47a900b4c4da3abfd28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| # { | |
| # "Id": "25cb95b8-af4c-4ccb-82d6-38843a9999c1", | |
| # "Name": "UUID Generator", | |
| # "Author": "qianlifeng", | |
| # "Version": "1.0.0", | |
| # "MinWoxVersion": "2.0.0", | |
| # "Description": "Generate various types of UUIDs", | |
| # "Icon": "emoji:π", | |
| # "TriggerKeywords": ["uuid"], | |
| # "SupportedOS": [ | |
| # "windows", | |
| # "linux", | |
| # "darwin" | |
| # ] | |
| # } | |
| """ | |
| UUID Generator Plugin for Wox | |
| Generates various types of UUIDs: | |
| - UUID v1: Time-based UUID | |
| - UUID v4: Random UUID (most common) | |
| - UUID v5: Name-based UUID using SHA-1 | |
| This plugin demonstrates using built-in actions (copy-to-clipboard). | |
| No need to implement handle_action() for built-in actions! | |
| """ | |
| import sys | |
| import json | |
| import uuid as uuid_lib | |
| def handle_query(params, request_id): | |
| """ | |
| Handle query requests | |
| Args: | |
| params: The parameters from the JSON-RPC request | |
| request_id: The ID of the JSON-RPC request | |
| Returns: | |
| A JSON-RPC response with the query results | |
| """ | |
| results = [] | |
| # Generate UUID v4 (random) | |
| uuid4_str = str(uuid_lib.uuid4()) | |
| results.append({ | |
| "title": uuid4_str, | |
| "subtitle": "UUID v4 (Random) - Click to copy", | |
| "icon": "emoji:π", | |
| "score": 100, | |
| "actions": [ | |
| { | |
| "name": "Copy", | |
| "id": "copy-to-clipboard", | |
| "text": uuid4_str | |
| } | |
| ] | |
| }) | |
| # Generate UUID v4 uppercase | |
| uuid4_upper = uuid4_str.upper() | |
| results.append({ | |
| "title": uuid4_upper, | |
| "subtitle": "UUID v4 (Uppercase) - Click to copy", | |
| "icon": "emoji:π", | |
| "score": 90, | |
| "actions": [ | |
| { | |
| "name": "Copy", | |
| "id": "copy-to-clipboard", | |
| "text": uuid4_upper | |
| } | |
| ] | |
| }) | |
| # Generate UUID v4 without hyphens | |
| uuid4_no_hyphen = uuid4_str.replace('-', '') | |
| results.append({ | |
| "title": uuid4_no_hyphen, | |
| "subtitle": "UUID v4 (No hyphens) - Click to copy", | |
| "icon": "emoji:π", | |
| "score": 80, | |
| "actions": [ | |
| { | |
| "name": "Copy", | |
| "id": "copy-to-clipboard", | |
| "text": uuid4_no_hyphen | |
| } | |
| ] | |
| }) | |
| # Return results | |
| return { | |
| "jsonrpc": "2.0", | |
| "result": { | |
| "items": results | |
| }, | |
| "id": request_id | |
| } | |
| def main(): | |
| """Main entry point for the script plugin""" | |
| # Parse input | |
| try: | |
| if len(sys.argv) > 1: | |
| # From command line arguments | |
| request = json.loads(sys.argv[1]) | |
| else: | |
| # From stdin | |
| request = json.loads(sys.stdin.read()) | |
| except json.JSONDecodeError as e: | |
| # Return parse error | |
| print(json.dumps({ | |
| "jsonrpc": "2.0", | |
| "error": { | |
| "code": -32700, | |
| "message": "Parse error", | |
| "data": str(e) | |
| }, | |
| "id": None | |
| })) | |
| return 1 | |
| # Validate JSON-RPC request | |
| if request.get("jsonrpc") != "2.0": | |
| print(json.dumps({ | |
| "jsonrpc": "2.0", | |
| "error": { | |
| "code": -32600, | |
| "message": "Invalid Request", | |
| "data": "Expected JSON-RPC 2.0" | |
| }, | |
| "id": request.get("id") | |
| })) | |
| return 1 | |
| # Handle different methods | |
| method = request.get("method") | |
| params = request.get("params", {}) | |
| request_id = request.get("id") | |
| if method == "query": | |
| response = handle_query(params, request_id) | |
| elif method == "action": | |
| # For built-in actions, we don't need to handle them | |
| # Just return empty result - Wox handles it automatically | |
| response = { | |
| "jsonrpc": "2.0", | |
| "result": {}, | |
| "id": request_id | |
| } | |
| else: | |
| # Method not found | |
| response = { | |
| "jsonrpc": "2.0", | |
| "error": { | |
| "code": -32601, | |
| "message": "Method not found", | |
| "data": f"Method '{method}' not supported" | |
| }, | |
| "id": request_id | |
| } | |
| # Output response | |
| print(json.dumps(response)) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Query in Wox to install:
wpm install UUID Generator