把个人博客放在了 netilfy 托管,它给了一个优化建议,可以压缩图片节省带宽。但是每次截图后都要再压缩下图片有点麻烦,于是想着应该可以偷偷懒。目标很明确,截图后图片传到我的 git 仓库 images 目录后,能给我自动压缩,并且上传 COS ,这样我就只用在 markdown 文件里面拼链接就好了。
脚本
on run {input, parameters}
set currentDate to do shell script "date '+%Y%m%d'"
tell application "System Events"
repeat with i in input
set filePath to POSIX path of i
set fileExtension to name extension of i
set folderName to do shell script "dirname " & filePath
if fileExtension is "png" then
set fileName to name of i
set AppleScript's text item delimiters to "."
set baseName to first text item of fileName
if baseName does not start with currentDate then
do shell script "/opt/homebrew/bin/pngquant --force --ext .png " & quoted form of filePath
set newBaseName to currentDate & "_" & baseName
set newFileName to newBaseName & "." & fileExtension
set name of i to newFileName
set newFilePath to folderName & "/" & newFileName
set uploadCommand to "/opt/homebrew/Caskroom/miniconda/base/bin/coscmd upload " & quoted form of newFilePath & " /"
do shell script uploadCommand
end if
end if
end repeat
end tell
end run
1
xuelang OP V2ex 请求 cos 图片,为啥不带 referer ,这里防盗链白名单加了也没用
|