Last active
October 12, 2023 04:53
-
-
Save radixm46/4ab0bfb8e28520ce8addb8fe4eeab9bd to your computer and use it in GitHub Desktop.
Converting PNG to JPG using sips and pbpaste on macOS for multiple paths
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
#!/usr/bin/env emacs --script | |
(cond ((eq system-type 'darwin) | |
(dolist (fpath (split-string (shell-command-to-string "pbpaste") "\n" t)) | |
(let* ((output (replace-regexp-in-string "\\(?:\\.\\w+\\)?$" ".jpg" fpath)) | |
(cmd (format "sips -s format jpeg -s formatOptions 80 \'%s\' --out \'%s\'" | |
fpath output))) | |
(when (and (file-exists-p fpath) | |
(string-match-p "\\.png\\'" fpath)) | |
(princ (format "=> cocnvert: %s\n" fpath)) | |
(shell-command cmd))))) | |
((eq system-type 'gnu/linux) | |
(unless (and (executable-find "wl-paste") | |
(executable-find "convert")) | |
(princ "requirements not satisfied, exit...") | |
(kill-emacs 1)) | |
(dolist (fpath (split-string (shell-command-to-string "wl-paste --no-newline") "\n" t)) | |
(let* ((output (replace-regexp-in-string "\\(?:\\.\\w+\\)?$" ".jpg" fpath)) | |
(cmd (format "convert \'%s\' \'%s\' -quality 80" | |
fpath output))) | |
(when (and (file-exists-p fpath) | |
(string-match-p "\\.png\\'" fpath)) | |
(princ (format "=> cocnvert: %s\n" fpath)) | |
(shell-command cmd))))) | |
(t (progn (princ "not supported system, exit...") | |
(kill-emacs 1)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment