unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Executing Emacs Lisp through AppleScript on Mac OS X?
@ 2005-12-17 11:11 Presto W
  2005-12-17 13:00 ` Lennart Borgman
  2005-12-17 13:28 ` Andreas Schwab
  0 siblings, 2 replies; 10+ messages in thread
From: Presto W @ 2005-12-17 11:11 UTC (permalink / raw)


Has anyone investigated what would be required to add support for
executing Lisp code inside a running Emacs application using
AppleScript?

I imagine this could work much the same way as Safari can take
JavaScript to execute:

tell application "Emacs"
  do Lisp "(switch-to-buffer \"*scratch*\")"
end tell

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2005-12-17 11:11 Executing Emacs Lisp through AppleScript on Mac OS X? Presto W
@ 2005-12-17 13:00 ` Lennart Borgman
  2005-12-17 13:41   ` Presto W
  2005-12-17 13:28 ` Andreas Schwab
  1 sibling, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2005-12-17 13:00 UTC (permalink / raw)
  Cc: emacs-devel

Presto W wrote:

>Has anyone investigated what would be required to add support for
>executing Lisp code inside a running Emacs application using
>AppleScript?
>  
>
I do not know Mac, but could not this be done by using emacsclient (or 
gnuclient)?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2005-12-17 11:11 Executing Emacs Lisp through AppleScript on Mac OS X? Presto W
  2005-12-17 13:00 ` Lennart Borgman
@ 2005-12-17 13:28 ` Andreas Schwab
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2005-12-17 13:28 UTC (permalink / raw)
  Cc: emacs-devel

Presto W <prestowk@gmail.com> writes:

> Has anyone investigated what would be required to add support for
> executing Lisp code inside a running Emacs application using
> AppleScript?

I don't know anything about AppleScript, but you can execute arbitrary
lisp expressions in the running Emacs with `emacsclient --eval', provided
you have started the server (see server-start).

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2005-12-17 13:00 ` Lennart Borgman
@ 2005-12-17 13:41   ` Presto W
  2005-12-18  3:54     ` YAMAMOTO Mitsuharu
  0 siblings, 1 reply; 10+ messages in thread
From: Presto W @ 2005-12-17 13:41 UTC (permalink / raw)
  Cc: emacs-devel

On 12/17/05, Lennart Borgman <lennart.borgman.073@student.lu.se> wrote:
> I do not know Mac, but could not this be done by using emacsclient (or
> gnuclient)?

Yes, certainly.  This could simply be seen as question of improving
the integration with the Mac environment:  it is natural for
applications to provide AppleScript interfaces for important
operations.  When part of a larger AppleScript job, it would be more
straightforward (and less errorprone) to call Emacs AppleScript
interfaces than building a command line and launching an external
process.

Just wanted to know if anyone else already thought of this or even
implemented it.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2005-12-17 13:41   ` Presto W
@ 2005-12-18  3:54     ` YAMAMOTO Mitsuharu
  2006-01-08 19:46       ` David Reitter
  0 siblings, 1 reply; 10+ messages in thread
From: YAMAMOTO Mitsuharu @ 2005-12-18  3:54 UTC (permalink / raw)
  Cc: emacs-devel

>>>>> On Sat, 17 Dec 2005 15:41:17 +0200, Presto W <prestowk@gmail.com> said:

> Just wanted to know if anyone else already thought of this or even
> implemented it.

Currently, underlying Apple event support is in the early stage and
too weak to support AppleScript in general.  It can react to incoming
Apple events, but cannot return results or error messages to the
caller.  If this limitation is OK with you, the implementation would
be as follows:

<?xml version="1.0"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="Emacs Terminology">
	<suite name="Emacs Suite" code="EMAx">
		<command name="do Lisp" code="EMAxLisp" description="Evaluate a Lisp expression.">
			<direct-parameter type="text" description="The expression to be evaluated."/>
		</command>
	</suite>
</dictionary>

(put 'emacs-suite 'mac-apple-event-class "EMAx")
(put 'do-lisp 'mac-apple-event-id "Lisp")

(defun mac-ae-do-lisp (event)
  (interactive "e")
  (eval (car (read-from-string (mac-ae-text (mac-event-ae event))))))

(define-key mac-apple-event-map [emacs-suite do-lisp] 'mac-ae-do-lisp)

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2005-12-18  3:54     ` YAMAMOTO Mitsuharu
@ 2006-01-08 19:46       ` David Reitter
  2006-01-08 20:24         ` Lennart Borgman
  2006-01-08 20:54         ` Michael Price
  0 siblings, 2 replies; 10+ messages in thread
From: David Reitter @ 2006-01-08 19:46 UTC (permalink / raw)
  Cc: Presto W, emacs-devel

On 18 Dec 2005, at 03:54, YAMAMOTO Mitsuharu wrote:

> (defun mac-ae-do-lisp (event)
>   (interactive "e")
>   (eval (car (read-from-string (mac-ae-text (mac-event-ae event))))))


Something like that is definitely an interesting functionality, but I  
wouldn't want to see it outside of a local installation, i.e. in  
Emacs, simply for security reasons. With such an event, any  
application can practically attain all rights that the Emacs process  
has and execute pretty much anything.

Some support for common functions would be nice, though.
For example, I stumbled over "Open Document"'s inability to find new  
files, i.e. only existing files can be opened.

Because the system's "open" command cannot pass arbitrary parameters  
either, I don't see a way to get (a running) Emacs to find a file (as  
opposed to opening an existing one) from external.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2006-01-08 19:46       ` David Reitter
@ 2006-01-08 20:24         ` Lennart Borgman
  2006-01-08 21:14           ` David Reitter
  2006-01-08 20:54         ` Michael Price
  1 sibling, 1 reply; 10+ messages in thread
From: Lennart Borgman @ 2006-01-08 20:24 UTC (permalink / raw)
  Cc: YAMAMOTO Mitsuharu, emacs-devel

David Reitter wrote:

> On 18 Dec 2005, at 03:54, YAMAMOTO Mitsuharu wrote:
>
>> (defun mac-ae-do-lisp (event)
>>   (interactive "e")
>>   (eval (car (read-from-string (mac-ae-text (mac-event-ae event))))))
>
>
>
> Something like that is definitely an interesting functionality, but I  
> wouldn't want to see it outside of a local installation, i.e. in  
> Emacs, simply for security reasons. With such an event, any  
> application can practically attain all rights that the Emacs process  
> has and execute pretty much anything.
>
> Some support for common functions would be nice, though.
> For example, I stumbled over "Open Document"'s inability to find new  
> files, i.e. only existing files can be opened.
>
> Because the system's "open" command cannot pass arbitrary parameters  
> either, I don't see a way to get (a running) Emacs to find a file (as  
> opposed to opening an existing one) from external.

Does not emacsclient have a -eval parameter?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2006-01-08 19:46       ` David Reitter
  2006-01-08 20:24         ` Lennart Borgman
@ 2006-01-08 20:54         ` Michael Price
  1 sibling, 0 replies; 10+ messages in thread
From: Michael Price @ 2006-01-08 20:54 UTC (permalink / raw)
  Cc: YAMAMOTO Mitsuharu, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 793 bytes --]

On 1/8/06, David Reitter <david.reitter@gmail.com> wrote:
> On 18 Dec 2005, at 03:54, YAMAMOTO Mitsuharu wrote:
>
> > (defun mac-ae-do-lisp (event)
> >   (interactive "e")
> >   (eval (car (read-from-string (mac-ae-text (mac-event-ae event))))))
>
> Something like that is definitely an interesting functionality, but I
> wouldn't want to see it outside of a local installation, i.e. in
> Emacs, simply for security reasons. With such an event, any
> application can practically attain all rights that the Emacs process
> has and execute pretty much anything.

Given that emacs isn't setuid anything, I'm having trouble imagining a
scenario on a Mac where your concern is actually a concern. Can you
provide an example?

Keep in mine you can also send apple events to the terminal :)

Michael

[-- Attachment #2: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2006-01-08 20:24         ` Lennart Borgman
@ 2006-01-08 21:14           ` David Reitter
  2006-01-09  2:21             ` YAMAMOTO Mitsuharu
  0 siblings, 1 reply; 10+ messages in thread
From: David Reitter @ 2006-01-08 21:14 UTC (permalink / raw)
  Cc: YAMAMOTO Mitsuharu, emacs-devel

On 8 Jan 2006, at 20:24, Lennart Borgman wrote:

>>  Because the system's "open" command cannot pass arbitrary  
>> parameters  either, I don't see a way to get (a running) Emacs to  
>> find a file (as  opposed to opening an existing one) from external.
>
> Does not emacsclient have a -eval parameter?

Yes, but you need to manually M-x server-start beforehand.

> Given that emacs isn't setuid anything, I'm having trouble imagining a
> scenario on a Mac where your concern is actually a concern. Can you
> provide an example?

I run Emacs via sudo every now and then to edit system files. There's  
your example.
Maybe I ought to use tramp mode instead.

Executing AppleScripts is restricted to the console user and root -  
what about sending Apple events?

> Keep in mine you can also send apple events to the terminal :)

... but Terminal will not execute those in the currently open shell,  
but open a new one.
With UI scripting you can do pretty much all nasty things, but UI  
scripting is not on by default (probably for that reason).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Executing Emacs Lisp through AppleScript on Mac OS X?
  2006-01-08 21:14           ` David Reitter
@ 2006-01-09  2:21             ` YAMAMOTO Mitsuharu
  0 siblings, 0 replies; 10+ messages in thread
From: YAMAMOTO Mitsuharu @ 2006-01-09  2:21 UTC (permalink / raw)
  Cc: Lennart Borgman, emacs-devel

>>>>> On Sun, 8 Jan 2006 21:14:32 +0000, David Reitter <david.reitter@gmail.com> said:

>> Keep in mine you can also send apple events to the terminal :)

> ... but Terminal will not execute those in the currently open shell,
> but open a new one.  With UI scripting you can do pretty much all
> nasty things, but UI scripting is not on by default (probably for
> that reason).

I think I didn't change any UI scripting settings on Mac OS X 10.4.3,
but the following script can execute the specified command in the
existing shell.

  tell application "Terminal" to activate
  tell application "System Events"
    tell process "Terminal"
      keystroke "date\n"
    end tell
  end tell

				     YAMAMOTO Mitsuharu
				mituharu@math.s.chiba-u.ac.jp

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2006-01-09  2:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-17 11:11 Executing Emacs Lisp through AppleScript on Mac OS X? Presto W
2005-12-17 13:00 ` Lennart Borgman
2005-12-17 13:41   ` Presto W
2005-12-18  3:54     ` YAMAMOTO Mitsuharu
2006-01-08 19:46       ` David Reitter
2006-01-08 20:24         ` Lennart Borgman
2006-01-08 21:14           ` David Reitter
2006-01-09  2:21             ` YAMAMOTO Mitsuharu
2006-01-08 20:54         ` Michael Price
2005-12-17 13:28 ` Andreas Schwab

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).