<?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"
	>

<channel>
	<title>Foo Hack &#187; Request</title>
	<atom:link href="http://foohack.com/category/request/feed/" rel="self" type="application/rss+xml" />
	<link>http://foohack.com</link>
	<description>Isaac Schlueter on Web Development</description>
	<pubDate>Fri, 29 Oct 2010 17:20:21 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
	<language>en</language>
			<item>
		<title>Applescript for iTerm (and a request for help with it)</title>
		<link>http://foohack.com/2007/10/applescript-for-iterm-and-a-request-for-help-with-it/</link>
		<comments>http://foohack.com/2007/10/applescript-for-iterm-and-a-request-for-help-with-it/#comments</comments>
		<pubDate>Mon, 01 Oct 2007 17:00:45 +0000</pubDate>
		<dc:creator>Isaac</dc:creator>
		
		<category><![CDATA[Freebie]]></category>

		<category><![CDATA[Request]]></category>

		<category><![CDATA[Tools of the Trade]]></category>

		<guid isPermaLink="false">http://foohack.com/2007/10/applescript-for-iterm-and-a-request-for-help-with-it/</guid>
		<description><![CDATA[iTerm is a major part of my workspace.  I&#8217;m a big fan of tabbed interfaces, and my fingers have gotten really good at the Apple-&#8592; and Apple-&#8594; key combos to swap between them.  I usually have three tabs going:



One that runs Unison in batch mode to keep my mac and BSD machines in <small><a href="http://foohack.com/2007/10/applescript-for-iterm-and-a-request-for-help-with-it/">...Read More</a></small>]]></description>
			<content:encoded><![CDATA[<p><a href="http://iterm.sourceforge.net/" rev="vote-for">iTerm</a> is a major part of my workspace.  I&#8217;m a big fan of tabbed interfaces, and my fingers have gotten really good at the Apple-&larr; and Apple-&rarr; key combos to swap between them.  I usually have three tabs going:</p>
<ol>
<li>One that runs <a href="http://www.cis.upenn.edu/~bcpierce/unison/" rev="vote-for">Unison</a> in batch mode to keep my mac and BSD machines in sync.  I set the title of this one to &#8220;unisoner&#8221;.</li>
<li>A second logged into my BSD machine in the package folder to easily relink the site package when I add files to it.  This is the &#8220;relinker&#8221;.  (Also, this one occasionally is used to <code>tail -f</code> on the apache log file.)</li>
<li>A third sitting in my code folder to do CVS updates, open files, grep for stuff, etc.  This is &#8220;cvser&#8221;.</li>
</ol>
<p>Of course, it&#8217;s a pain to go through the steps to set all this up.  So, I wrote this Applescript, and it does it all:</p>
<p><code class="block applescript">tell Application "iTerm"<br />
&nbsp;&nbsp;activate<br />
&nbsp;&nbsp;set myterm to (make new terminal)<br />
&nbsp;&nbsp;tell myterm<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (count of sessions) < 3 then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my open_tab("title unisoner<br />
cd dev/orion<br />
unisonpush<br />
unisondev")<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my open_tab("v<br />
yroot orion_front<br />
title relinker-tailer<br />
cd dev/orion/front/package<br />
yapl")<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my open_tab("title cvser<br />
cd dev/orion<br />
open -a TextMate orion.tmproj")<br />
&nbsp;&nbsp;&nbsp;&nbsp;end if<br />
&nbsp;&nbsp;end tell<br />
&nbsp;&nbsp;terminate first session of current terminal<br />
end tell<br />
on open_tab(command)<br />
&nbsp;&nbsp;tell Application "iTerm" to tell first terminal<br />
&nbsp;&nbsp;&nbsp;&nbsp;launch session "Default Session"<br />
&nbsp;&nbsp;&nbsp;&nbsp;tell last session<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;write text command<br />
&nbsp;&nbsp;&nbsp;&nbsp;end tell<br />
&nbsp;&nbsp;end tell<br />
end run_command</code></p>
<p>The only problem is, it requests a password when it ssh&#8217;es into my dev box and changes to the project root.  So, that whole piece falls down.</p>
<p>Anyone out there in geek land know of a way to make an Applescript respond to things like that?  Something like this:</p>
<p></code><code class="block applescript broken">whenever the last line is "Password:" then<br />
&nbsp;&nbsp;write text returned of (display dialog "Password:" default answer "")<br />
end if</code></p>
<h3>Update:</h3>
<p>Turns out, what I suggested is pretty close to what works.  However, since there&#8217;s no event to listen for that would tell the script that the display has been updated, it takes a bit of fudging, and doesn&#8217;t always work perfectly.  Basically, you put <code>@@@PASSWORD@@@</code> in the list of commands where you may expect a password prompt, and it&#8217;ll wait for a second and display a dialog if necessary.</p>
<p><code class="block applescript"><br />
on open_tab(command)<br />
&nbsp;&nbsp;set commands to paragraphs in command<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;tell Application "iTerm" to tell first terminal<br />
&nbsp;&nbsp;&nbsp;&nbsp;launch session "Default Session"<br />
&nbsp;&nbsp;&nbsp;&nbsp;repeat with currentCommand in commands<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (text of currentCommand = "@@@PASSWORD@@@") then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do shell script "sleep 1"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set pw to last word of (get contents of last session)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if pw = "Password" then<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tell Application "Finder"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;activate<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set pw to text returned of (display dialog "Password:" default answer "" with hidden answer)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end tell<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tell Application "iTerm" to activate<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tell last session to write text pw<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tell last session to write text currentCommand<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;end repeat<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;end tell<br />
end open_tab</code></p>
<p>Get the finished product: <a href='http://foohack.com/blog/wp-content/uploads/2007/10/workspace.applescript' title='Applescript for iTerm'>Applescript for iTerm</a>.  You&#8217;ll want to change up the specific commands up near the top, of course.</p>
]]></content:encoded>
			<wfw:commentRss>http://foohack.com/2007/10/applescript-for-iterm-and-a-request-for-help-with-it/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.135 seconds -->

