Created
October 30, 2023 01:43
-
-
Save selfboot/52d5746e238db8a5b294647abba19a45 to your computer and use it in GitHub Desktop.
mac automator tool,Monitor folder, automatically compress and upload images to COS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
set fileName to name of i | |
set AppleScript's text item delimiters to "." | |
set baseName to first text item of fileName | |
set regexMatch to do shell script "if [[ " & baseName & " =~ ^[0-9]{8}_ ]]; then echo 'true'; else echo 'false'; fi" | |
if fileExtension is "png" and regexMatch is "false" 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 | |
else if fileExtension is in {"webp", "jpeg", "gif"} and regexMatch is "false" then | |
set newBaseName to currentDate & "_" & baseName | |
set newFileName to newBaseName & "." & fileExtension | |
set name of i to newFileName | |
set newFilePath to folderName & "/" & newFileName | |
else if regexMatch is "true" then | |
set newFilePath to filePath | |
end if | |
set uploadCommand to "/opt/homebrew/Caskroom/miniconda/base/bin/coscmd upload " & quoted form of newFilePath & " /" | |
do shell script uploadCommand | |
end repeat | |
end tell | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that the coscmd path(/opt/homebrew/Caskroom/miniconda/base/bin/coscmd) is changed to your own.