7

GPT4 帮我实现 Mac 图片自动压缩上传 COS

 1 year ago
source link: https://www.v2ex.com/t/945601
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  OpenAI

GPT4 帮我实现 Mac 图片自动压缩上传 COS

  xuelang · selfboot · 3 小时 52 分钟前 · 375 次点击

把个人博客放在了 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

完整内容


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK