<?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>Transcending Frontiers &#187; Prompting for a password with Applescript</title>
	<atom:link href="http://blog.thefrontiergroup.com.au/tag/sudo/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.thefrontiergroup.com.au</link>
	<description>Your peek inside the collective mind of The Frontier Group</description>
	<lastBuildDate>Tue, 03 Jan 2012 06:53:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Prompting for a password with Applescript</title>
		<link>http://blog.thefrontiergroup.com.au/2008/12/prompting-for-a-password-with-applescript/</link>
		<comments>http://blog.thefrontiergroup.com.au/2008/12/prompting-for-a-password-with-applescript/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 05:50:19 +0000</pubDate>
		<dc:creator>mlambie</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[management]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[sudo]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=211</guid>
		<description><![CDATA[Further to my previous foray into the world of Applescript, I&#8217;ve modified my server management script to now prompt me for a sudo password. Previously I would have to tab between each Terminal window and enter my sudo password, but now I enter it once and a dynamic command is generated that looks like this: [...]]]></description>
			<content:encoded><![CDATA[<p>Further to my <a href="http://thefrontiergroup.com.au/blog/2008/11/managing-multiple-ubuntu-servers-painlessly/">previous foray into the world of Applescript</a>, I&#8217;ve modified my server management script to now prompt me for a sudo password. Previously I would have to tab between each Terminal window and enter my sudo password, but now I enter it once and a dynamic command is generated that looks like this:</p>
<p><code>echo &lt;password&gt; | sudo -S clear &#038;&#038; sudo aptitude update &#038;&#038; sudo aptitude dist-upgrade &#038;&#038; sudo aptitude clean'"</code></p>
<p>I don&#8217;t like that my sudo password is displayed on the screen. I could get around this by manually editing <code>/etc/sudoers</code> to allow for password-less aptitude. Alternatively, perhaps I could encrypt my password inside the Applescript and send it, pre-encrypted, to sudo. They&#8217;re options I guess.</p>
<p>You&#8217;ll notice that the first thing I do is clear the screen, but when there&#8217;s a second or so lag it means my password is bare for all to see. I&#8217;ll consider that when I run the script.</p>
<p>Below is an Applescript snippet which shows you how to open a dialog box and take some simple text input:</p>
<pre name="code" class="php">set my_password to display dialog "Please enter your password:" ¬
	with title "Password" ¬
	with icon caution ¬
	default answer "" ¬
	buttons {"Cancel", "OK"} default button 2 ¬
	giving up after 295 ¬
	with hidden answer
if length of (text returned of my_password) is not 0 then
	display dialog "Running the application!" buttons ["OK"] default button 1
else
	display dialog "You didn't enter a sudo password!" buttons ["OK"] default button 1
end if</pre>
<p>Having spent a bit of time with Ruby lately, I don&#8217;t like the syntax of Applescript very much, though it gets the job done.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2008/12/prompting-for-a-password-with-applescript/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2008/12/prompting-for-a-password-with-applescript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

