<?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/applescript/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>
		<item>
		<title>Managing multiple Ubuntu servers painlessly</title>
		<link>http://blog.thefrontiergroup.com.au/2008/11/managing-multiple-ubuntu-servers-painlessly/</link>
		<comments>http://blog.thefrontiergroup.com.au/2008/11/managing-multiple-ubuntu-servers-painlessly/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 03:55:34 +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[dist-upgade]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://thefrontiergroup.com.au/blog/?p=164</guid>
		<description><![CDATA[Like most programmers, I don&#8217;t like to repeat manual tasks, well, manually. We use Ubuntu Server almost exclusively on our servers and whilst package management is very simple (login, aptitude update, aptitude dist-upgrade, all done) when you have to look after many (fourteen and expanding) servers it can get repetitive. I use Terminal (or is it [...]]]></description>
			<content:encoded><![CDATA[<p>Like most programmers, I don&#8217;t like to repeat manual tasks, well, manually. We use Ubuntu Server almost exclusively on our servers and whilst package management is very simple (login, <code>aptitude update</code>, <code>aptitude dist-upgrade</code>, all done) when you have to look after many (fourteen and expanding) servers it can get repetitive.</p>
<p>I use Terminal (or is it called Terminal.app?) on Mac OS X as my terminal emulator, and I&#8217;ve messed around with using <a href="http://lambie.org/2007/11/03/tabs-in-terminal-using-applescript-on-leopard/">Applescript to open multiple tabs</a> before, so I figured this was a problem worthy of a Sunday-morning.</p>
<p>What I envisaged was iterating over a list of servers and having Applescript manage a Terminal instance, opening new tabs where appropriate, and executing the upgrade command in each tab for each server. Sounds simple enough.</p>
<p>And it was. I used <a href="http://burnfield.com/martin/2008/07/12/my-terminal-setup-for-rails-development/">Martin Ström&#8217;s excellent article</a> as a base for my script, and ended up with the following:</p>
<pre name="code" class="php">set tab_count to 0
set servers to {"astrotrain", "bumblebee", "grimlock", "ironhide", ¬
	"jazz", "laserbeak", "mirage", "prime", ¬
	"prowl", "ratchet", "ravage", "rumble", ¬
	"soundwave", "wheeljack"}
-- Update the package list, dist-upgrade and remove the downloaded
-- packages so they're not included in the backups
set dist_upgrade to ¬
	" 'sudo aptitude update &#038;&#038;
	  sudo aptitude dist-upgrade &#038;&#038;
	  sudo aptitude clean'"

-- Make our settings globally available
global tab_count, servers, dist_upgrade

-- Mainline
on main()
	tell application "Terminal"
		activate
		repeat with server in servers
			set cmd to "ssh -t " &#038; server &#038; dist_upgrade &#038; " &#038;&#038; exit"
			my open_tab(cmd)
		end repeat
	end tell
end main

on open_tab(cmd)
	tell application "Terminal" to activate
	my create_new_window_or_tab()
	tell application "Terminal" to ¬
		do script with command (cmd) in last tab of window 1
end open_tab

on create_new_window_or_tab()
	if tab_count ≤ 0 then
		tell application "Terminal" to do script ""
		set tab_count to tab_count + 1
	else
		tell application "System Events" to ¬
			tell process "Terminal" to ¬
				keystroke "t" using command down
	end if
end create_new_window_or_tab

-- Run the mainline
main()</pre>
<p>Apologies for the highlighting &#8211; the plugin doesn&#8217;t understand Applescript.</p>
<script src="http://feeds.feedburner.com/~s/TranscendingFrontiers?i=http://blog.thefrontiergroup.com.au/2008/11/managing-multiple-ubuntu-servers-painlessly/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://blog.thefrontiergroup.com.au/2008/11/managing-multiple-ubuntu-servers-painlessly/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

