alfred 配合 picgo 图床上传图片
需要实现的功能是:alfred 快捷键通过 picgo 直接上传剪切板中的图片
前提:
安装 pngpaste
brew install pngpaste jq
1. 开启 picgo http 上传
2. 创建 alfred workflow 工作流
一个 script filter 将结果处理后传递到粘贴板中
核心逻辑
mkdir -p /tmp/alfred-tc/
rm /tmp/alfred-tc/*
now=$(date +%Y-%m-%d:%H:%M:%S)
tmp_path=/tmp/alfred-tc/$now.png
p_log=/tmp/alfred-tc/$now.png.log
pngpaste - >>$tmp_path &>$p_log
if [ "$?" != "0" ]
then
pres=$(cat $p_log)
cat <<EOF
{"items": [
{
"uid": "item0",
"title": "$pres",
"subtitle": "上传图片出错"
}
]}
EOF
exit 0
fi
request=<<EOF
{
"list":[
"$tmp_path"
]
}
EOF
res=`curl --location --request POST "${picgo_http_url}" \
--header 'Content-Type: application/json' \
--data-raw "$request"`
img_url=$(echo $res | jq -r '.result[0]')
cat <<EOF
{"items": [
{
"uid": "item0",
"title": "$img_url",
"subtitle": "上传图片原始链接",
"icon":"$img_url",
"arg":"$img_url"
},
{
"uid": "item1",
"title": "$img_url",
"subtitle": "上传图片markdown链接",
"icon":"$img_url",
"arg":"![img]($img_url)"
}
]}
EOF
当当前粘贴板中没有图片时的提示
有图片的上传结果
这样即可实现工作流快捷上传 更多小工具见 https://github.com/SoulSu/alfred-workflow