<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lojic Technologies Blog &#187; applescript</title>
	<atom:link href="http://lojic.com/blog/tag/applescript/feed/" rel="self" type="application/rss+xml" />
	<link>http://lojic.com/blog</link>
	<description></description>
	<lastBuildDate>Fri, 28 May 2010 16:11:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Send Growl Notifications From Carbon Emacs On OSX</title>
		<link>http://lojic.com/blog/2009/08/06/send-growl-notifications-from-carbon-emacs-on-osx/</link>
		<comments>http://lojic.com/blog/2009/08/06/send-growl-notifications-from-carbon-emacs-on-osx/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 11:42:52 +0000</pubDate>
		<dc:creator>Brian Adkins</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[emacs]]></category>

		<guid isPermaLink="false">http://lojic.com/blog/?p=666</guid>
		<description><![CDATA[I found a handy article for sending growl notifications from Emacs and made some modifications for my particular setup.
Step One: Register Emacs with Growl
We need to register Carbon Emacs with Growl. This is a one time setup task. The following AppleScript script can be run in Script Editor.

tell application "GrowlHelperApp"
	-- Declare a list of notification [...]]]></description>
			<content:encoded><![CDATA[<p>I found <a href="http://alexott.blogspot.com/2008/11/working-with-growl-from-emacs.html">a handy article</a> for sending <a href="http://growl.info/">growl notifications</a> from <a href="http://homepage.mac.com/zenitani/emacs-e.html">Emacs</a> and made some modifications for my particular setup.</p>
<p><strong>Step One: Register Emacs with Growl</strong><br />
We need to register Carbon Emacs with Growl. This is a one time setup task. The following AppleScript script can be run in Script Editor.</p>
<pre class="code">
tell application "GrowlHelperApp"
	-- Declare a list of notification types
	set the allNotificationsList to {"Emacs Notification"}

	-- Declare list of active notifications.  If some of them
	-- isn't activated, user can do this later via preferences
	set the enabledNotificationsList to {"Emacs Notification"}

	-- Register our application in Growl.
	register as application "Emacs.app" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Emacs.app"
end tell
</pre>
<p><strong>Step Two: Create Growl Notification Script</strong><br />
This is a template of the AppleScript that will be used in the Emacs Lisp function. It can be tested by executing it in the Script Editor.</p>
<pre class="code">
tell application "GrowlHelperApp"
	notify with name "Emacs Notification" title "Emacs alert" description "Message!!!" application name "Emacs.app"
end tell
</pre>
<p><strong>Step Three: Emacs Lisp Function</strong><br />
Create an Emacs Lisp function that can be invoked with a title and message.</p>
<pre class="code">
(defun bja-growl-notification (title message &#038;optional sticky)
  "Send a Growl notification"
  (do-applescript
   (format "tell application \"GrowlHelperApp\"
              notify with name \"Emacs Notification\" title \"%s\" description \"%s\" application name \"Emacs.app\" sticky %s
           end tell"
           title
           (replace-regexp-in-string "\"" "''" message)
           (if sticky "yes" "no"))))
</pre>
<p>This can be tested with the following function which sends two growl notifications. The &#8220;sticky&#8221; one requires an explicit dismissal.</p>
<pre class="code">
(defun bja-growl-test ()
  (interactive)
  (bja-growl-notification "Emacs Notification" "This is my message")
  (bja-growl-notification "Emacs Notification" "This is my sticky message" t))
</pre>
<p><strong>UPDATE:</strong> I noticed bja-growl-notification was failing if the message had embedded double quotes, so I added a call to replace-regexp-in-string to replace them with two apostrophes.</p>
<p><strong>UPDATE 2:</strong> My main motivation for setting this up was to be able to generate growl notifications from ERC (Emacs IRC client). However, I quickly realized that having a generic reminder that I can easily fire up from within Emacs is very handy. Here&#8217;s the code:</p>
<pre class="code">
(defun bja-growl-timer (minutes message)
  "Issue a Growl notification after specified minutes"
  (interactive (list (read-from-minibuffer "Minutes: " "10")
                     (read-from-minibuffer "Message: " "Reminder") ))
  (run-at-time (* (string-to-number minutes) 60)
               nil
               (lambda (minutes, message)
                 (bja-growl-notification "Emacs Reminder" message t))
               minutes
               message))
</pre>
]]></content:encoded>
			<wfw:commentRss>http://lojic.com/blog/2009/08/06/send-growl-notifications-from-carbon-emacs-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
