[OS X Emacs] Aquamacs and applescript
david.reitter at gmail.com
Tue May 13 06:46:03 EDT 2008
On 13 May 2008, at 10:01, Daniel Stegmueller wrote:
> Hello List,
> I have a function using applescript to copy marked parts of a file
> into an external application. It worked with (Carbon) Emacs but
> does not work with Aquamacs.
> Is there an obvious error that I am missing?
Yes, your code is buggy.
The code relies on `copy-region-as-kill' to copy text into the system-
wide pasteboard, which it only does if certain other conditions are
The code below should do what you want.
I don't have Stata (I'm an R person), so I couldn't test the whole
http://aquamacs.org -- Aquamacs: Emacs on Mac OS X
http://aquamacs.org/donate -- Could we help you? Return the favor and
support the Aquamacs Project!
(defun ado-send-region-to-Stata ()
(clipboard-kill-ring-save (point) (mark))
(do-applescript "try \r tell application \"Finder\" \r set
theDummyDo to (((path to desktop folder) as text) & \".eraseme.do\")
\r set theContents to the clipboard \r if not (the last character of
theContents = return) then \r set theContents to theContents & return
\r end if \r end tell \r try \r set the open_target_file to open for
access file theDummyDo with write permission \r set eof of the
open_target_file to 0 \r write theContents to the open_target_file
starting at eof \r close access the open_target_file \r on error \r
try \r close access file theDummyDo \r end try \r end try \r tell
application \"StataSE\" \r activate \r open file theDummyDo \r end
tell \r on error error_message number error_number \r return \"Error:
\" & error_number & \". \" & error_message & return \r end try"))
More information about the MacOSX-Emacs