Creating an iOS Shortcut to create a GitHub Gist from the Markdown content in your clipboard involves several steps. Here’s a guide to accomplish this:
-
Generate a GitHub Personal Access Token:
- Ensure you have a GitHub Personal Access Token with the
gist
scope.
- Ensure you have a GitHub Personal Access Token with the
-
Prepare the Script:
- Use a Python script that takes input from the clipboard and creates a Gist. This script can be run using a web service like PythonAnywhere or a similar service that can execute scripts via a URL.
-
Create the iOS Shortcut:
- Use the Shortcuts app on iOS to create a new shortcut that copies the clipboard content and sends it to your script via a web request.
-
Sign up or log in to PythonAnywhere.
-
Create a new Python file with the following content:
from flask import Flask, request, jsonify import requests import json app = Flask(__name__) # Replace with your GitHub Personal Access Token GITHUB_TOKEN = 'your_personal_access_token' @app.route('/create_gist', methods=['POST']) def create_gist(): content = request.json.get('content') description = request.json.get('description', 'Gist created via iOS Shortcut') gist_data = { "description": description, "public": True, "files": { "file.md": { "content": content } } } headers = { 'Authorization': f'token {GITHUB_TOKEN}', 'Accept': 'application/vnd.github.v3+json' } response = requests.post('https://api.github.com/gists', headers=headers, data=json.dumps(gist_data)) if response.status_code == 201: return jsonify({"success": True, "url": response.json()['html_url']}) else: return jsonify({"success": False, "error": response.content}), response.status_code if __name__ == '__main__': app.run(host='0.0.0.0', port=5000)
-
Save the file and configure the web app to run this script on PythonAnywhere.
-
Open the Shortcuts app on your iOS device.
-
Create a new shortcut by tapping the "+" icon.
-
Add the "Get Clipboard" action:
- Search for "Get Clipboard" and add it to your shortcut.
-
Add the "Text" action:
-
Add the "Text" action and set it to a JSON template. Use the following template:
{ "content": "clipboard text" }
-
-
Add the "Replace Text" action:
- Replace "clipboard text" with the variable from the "Get Clipboard" action.
-
Add the "URL" action:
- Set the URL to the endpoint of your PythonAnywhere web app, e.g.,
https://yourusername.pythonanywhere.com/create_gist
.
- Set the URL to the endpoint of your PythonAnywhere web app, e.g.,
-
Add the "Get Contents of URL" action:
- Configure it to use the POST method and set the request body type to JSON.
- Set the JSON body to the variable from the "Replace Text" action.
-
Add the "Show Result" action:
- Show the result of the "Get Contents of URL" action.
-
Name your shortcut and save it.
- Get Clipboard
- Text:
{ "content": "clipboard text" }
- Replace Text:
- Replace "clipboard text" with the clipboard variable.
- URL:
https://yourusername.pythonanywhere.com/create_gist
- Get Contents of URL:
- Method: POST
- Headers: Content-Type: application/json
- Request Body: JSON
- Body: Variable from "Replace Text"
- Show Result
Now, when you copy Markdown text to your clipboard and run this shortcut, it will create a Gist on GitHub with the content of your clipboard.
By following these steps, you can create a powerful iOS Shortcut to automate the creation of GitHub Gists from Markdown content copied to your clipboard.