Typora 粘贴图片时 PicGo 弹窗的解决方案

Typora 每次粘贴图片时都跳出 PicGo 窗口的解决方案

问题说明

Typora 使用 PicGo.app 作为图片上传服务时,每次粘贴图片上传,PicGo 主窗口都会弹出,打断写作。即使将 PicGo 设为静默启动,仍可能出现这一现象。

本方案将 Typora 的上传服务改为 自定义命令,通过脚本直接调用 PicGo 的本地上传服务,使图片在后台上传,避免重复启动 PicGo 导致主窗口弹出。

以下步骤默认已安装 PicGo,并已配置好图床及所需插件。

本地环境

项目 版本或配置
操作系统 macOS 26.6.2
架构 Apple Silicon(arm64)
Typora 1.14.10
PicGo 3.0.3,已安装于 /Applications/PicGo.app
Python 3.9.6,解释器路径为 /usr/bin/python3
上传服务 PicGo-Server,127.0.0.1:36677

脚本保存路径

text 复制代码
~/Library/Application Support/Typora/typora-picgo-background.py

完整路径示例(请替换用户名):

text 复制代码
/Users/你的用户名/Library/Application Support/Typora/typora-picgo-background.py

配置步骤

  1. 在 PicGo 设置中,将启动模式设为 静默启动 ,关闭 显示 Dock 栏图标 ,保留 显示顶部栏图标。
  2. 开启 PicGo-Server ,监听地址设为 127.0.0.1,端口设为 36677。
  3. 在终端执行以下命令,创建目录并打开脚本文件:
sh 复制代码
mkdir -p "$HOME/Library/Application Support/Typora"
nano "$HOME/Library/Application Support/Typora/typora-picgo-background.py"
  1. 粘贴下方完整脚本代码,按 Control + O、回车保存,按 Control + X 退出。
  2. 打开 Typora → 偏好设置 → 图像 ,将 插入图片时... 设为 上传图片 ,勾选 对本地位置的图片应用上述规则。
  3. 将 上传服务 设为 自定义命令,填写:
sh 复制代码
/usr/bin/python3 "/Users/你的用户名/Library/Application Support/Typora/typora-picgo-background.py"

将 你的用户名 替换为自己的 macOS 用户名,保留路径两侧的双引号。需要有可用的 Python 3;若解释器安装在其他位置,将 /usr/bin/python3 替换为其完整路径。

脚本代码

python 复制代码
#!/usr/bin/python3
"""Upload through the existing PicGo server without activating its window."""
import json
import sys
import time
import subprocess
import urllib.request
import urllib.error

ENDPOINT = "http://127.0.0.1:36677"
HTTP = urllib.request.build_opener(urllib.request.ProxyHandler({}))

def ready():
    try:
        HTTP.open(ENDPOINT, timeout=1).close()
        return True
    except urllib.error.HTTPError:
        return True
    except (urllib.error.URLError, OSError):
        return False

def main():
    paths = sys.argv[1:]
    if not paths:
        raise RuntimeError("No image paths supplied; clipboard upload is disabled.")
    if not ready():
        subprocess.run(["/usr/bin/open", "-g", "-a", "/Applications/PicGo.app"], check=True)
        for _ in range(100):
            if ready():
                break
            time.sleep(0.2)
        else:
            raise RuntimeError("PicGo server did not start on port 36677.")
    request = urllib.request.Request(ENDPOINT + "/upload",
        data=json.dumps({"list": paths}).encode(),
        headers={"Content-Type": "application/json"}, method="POST")
    with HTTP.open(request, timeout=180) as response:
        result = json.load(response)
    urls = result.get("result", [])
    if not result.get("success") or len(urls) != len(paths):
        raise RuntimeError("PicGo upload failed: " + str(result.get("message", result.get("msg", "Check PicGo logs"))))
    if not all(isinstance(url, str) and url.startswith(("https://", "http://")) for url in urls):
        raise RuntimeError("PicGo returned invalid image URLs.")
    print("\n".join(urls))

if __name__ == "__main__":
    try:
        main()
    except Exception as error:
        print(str(error), file=sys.stderr)
        sys.exit(1)
相关推荐
RobinDevNotes2 天前
24GB Mac 做数字人:声音放本地,画面租云端
人工智能·python·macos·开发工具
oil欧哟4 天前
Oil Studio 的产品思路与日常使用方式:在 Mac 上录口播演示,并接入 AI Agent 精剪与自动录屏
人工智能·macos
小毛球.6 天前
第 3 篇:IDEA 最新版下载与完整安装教程(Mac)
java·macos·intellij-idea·idea
CodeClimb7 天前
Mac 磁盘无法推出(DMG外接盘)排查处理教程
macos
Karl_fang8 天前
🥳 再也不用拿起手机抄验证码!我做了一个 Android → Mac 的「验证码接力」工具
前端·macos·ai编程
csdn_aspnet9 天前
macOS 10 、Docker 玩轉 MySQL
运维·mysql·macos·docker·容器·mac
秋雨梧桐叶落莳9 天前
【iOS】Block底层详解
macos·ios·cocoa
高调的涵涵11 天前
café 和 café 不是一个文件名
macos
独隅13 天前
WebStorm macOS 安装部署与高效调优完全指南
ide·macos·webstorm
独隅14 天前
WebStorm macOS 安装调优与实战效能全景
ide·macos·webstorm