Created
January 31, 2011 14:34
-
-
Save nbqx/804101 to your computer and use it in GitHub Desktop.
toriaezu
This file contains hidden or 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
;;exec ExtendScript for InDesignCS4 and IllustratorCS4 via Emacs | |
(defvar cs:tmp-dir "/tmp/extscrt") | |
(defvar cs:tmp-file (concat cs:tmp-dir "/" "tmp.jsx")) | |
(defvar cs:app-scrt (concat cs:tmp-dir "/" "proc.scpt")) | |
(defvar cs:log-file (concat cs:tmp-dir "/" "tmp.log")) | |
(defvar cs:display-log-buffer "*CS4-log*") | |
;;respect to... | |
;;https://github.com/kanemu/extendscript-tmbundle/blob/master/Commands/Run%20CS4.tmCommand | |
(defvar cs:override-scrt (concat "var file=new File('" | |
cs:log-file "');file.encoding='UTF8';file.lineFeed='Mac';file.open('w');" | |
"$.write=function(){file.seek(0,2);file.write(arguments[0])};" | |
"$.writeln=function(){file.seek(0,2);file.writeln(arguments[0])};")) | |
(defvar ind:scrt-template (concat | |
"tell application \"Adobe InDesign CS4\"\n" | |
"activate\n" | |
"do script \"" cs:override-scrt "$.evalFile('" cs:tmp-file "')\" language javascript\n" | |
"end tell")) | |
(defvar ill:scrt-template (concat | |
"tell application \"Adobe Illustrator CS4\"\n" | |
"activate\n" | |
"do javascript \"" cs:override-scrt "$.evalFile('" cs:tmp-file "')\"\n" | |
"end tell")) | |
(defun cs:create-appscrt (ind-scrt) | |
(let ((scrt ind-scrt)) | |
(with-current-buffer (get-buffer-create "*appscrt*") | |
(erase-buffer) | |
(insert scrt) | |
(write-region (point-min) (point-max) cs:app-scrt)) | |
(kill-buffer "*appscrt*"))) | |
(defun cs:has-appscrt (scrt-template) | |
(progn | |
(unless (file-exists-p cs:tmp-dir) (make-directory cs:tmp-dir)) | |
(if (file-exists-p cs:app-scrt) (delete-file cs:app-scrt)) | |
(cs:create-appscrt scrt-template))) | |
(defun cs:display-result () | |
(unless (= (nth 7 (file-attributes cs:log-file)) 0) | |
(progn | |
(pop-to-buffer cs:display-log-buffer) | |
(erase-buffer) | |
(insert-file-contents cs:log-file)))) | |
(defun ind:do-script () | |
(interactive) | |
(progn | |
(cs:has-appscrt ind:scrt-template) | |
(write-region (point-min) (point-max) cs:tmp-file) | |
(shell-command (concat "arch -i386 osascript " cs:app-scrt)) | |
(cs:display-result))) | |
(defun ill:do-script () | |
(interactive) | |
(progn | |
(cs:has-appscrt ill:scrt-template) | |
(write-region (point-min) (point-max) cs:tmp-file) | |
(shell-command (concat "arch -i386 osascript " cs:app-scrt)))) | |
(provide 'extscrt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment