<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>CodeSnippets: CodeDrive Snippets courtesy of Peter Coopers handy little app</title>
    <link>http://codesnippets.joyent.com/rss</link>
    <pubDate>Wed, 06 Aug 2008 17:37:03 GMT</pubDate>
    <description>CodeSnippets: CodeDrive Snippets courtesy of Peter Coopers handy little app</description>
    <item>
      <title>Sorting arrays in Bash</title>
      <link>http://codesnippets.joyent.com/posts/show/1592</link>
      <description>&lt;code&gt;&lt;br /&gt;export PATH="$(/usr/sbin/sysctl -n user.cs_path)"&lt;br /&gt;&lt;br /&gt;export IFS=$'\n'&lt;br /&gt;#export IFS=$' \t\n'&lt;br /&gt;&lt;br /&gt;ar1=('g h c' abc def 123)&lt;br /&gt;ar2=('1 2 3' ABC ghc DEF)&lt;br /&gt;ar3=('-x' '! &amp; ?' $'a test\nsentence' $'another test\nsentence\n.' a64bitapp a32bitapp)&lt;br /&gt;&lt;br /&gt;printf "%s\n" "${#ar1[@]}" "${#ar2[@]}" "${#ar3[@]}"  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# ar3&lt;br /&gt;for ((i=0; i &lt; "${#ar3[@]}"; i++)); do echo "${ar3[$i]}"; done | sort | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar3[@]}"; i++)); do echo ${ar3[$i]}; done | sort | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar3[@]}"; i++)); do echo "${ar3[$i]}" | ruby -0777 -n -e 'p $_.to_s'; done | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar3[@]}"; i++)); do printf -- "${ar3[$i]}\n" | ruby -0777 -n -e 'p $_.to_s'; done | nl&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# sort a single array&lt;br /&gt;ar3sorted=( $(for ((i=0; i &lt; "${#ar3[@]}"; i++)); do echo ${ar3[$i]}; done | sort) )&lt;br /&gt;for ((i=0; i &lt; "${#ar3sorted[@]}"; i++)); do echo "${ar3sorted[$i]}" | ruby -0777 -n -e 'p $_.to_s'; done | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar3sorted[@]}"; i++)); do printf "%s\n" "${ar3sorted[$i]}" | ruby -0777 -n -e 'p $_.to_s'; done | nl&lt;br /&gt;&lt;br /&gt;ar3sorted=( $(printf "%s\000\n" "${ar3[@]}" | sed -e :a -e '$!N; s/\n/NEWLINE/g; ta' | tr '\000' '\n' | sed -e 's/^NEWLINE//' | sort) )&lt;br /&gt;for ((i=0; i &lt; "${#ar3sorted[@]}"; i++)); do printf -- "${ar3sorted[$i]//NEWLINE/\n}" | ruby -0777 -n -e 'p $_.to_s'; done | nl&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# sort multiple arrays; convert embedded newline characters into single spaces&lt;br /&gt;ar4=( $(printf "%s\n\000" "${ar1[@]}" "${ar2[@]}" "${ar3[@]}" | tr '\n' ' ' | tr '\000' '\n' | sort) )&lt;br /&gt;&lt;br /&gt;# sort multiple arrays; preserve embedded newline characters as NEWLINE&lt;br /&gt;ar4=( $(printf "%s\000\n" "${ar1[@]}" "${ar2[@]}" "${ar3[@]}" | sed -e :a -e '$!N; s/\n/NEWLINE/g; ta' | tr '\000' '\n' | sed -e 's/^NEWLINE//' | sort) )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;printf "%s\n" "${#ar4[@]}"  &lt;br /&gt;printf "%s\n" "${ar4[@]}" | nl  &lt;br /&gt;&lt;br /&gt;for ((i=0; i &lt; "${#ar4[@]}"; i++)); do echo ${ar4[$i]//NEWLINE/\\n}; done | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar4[@]}"; i++)); do echo -e ${ar4[$i]//NEWLINE/\\n}; done | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar4[@]}"; i++)); do printf -- ${ar4[$i]//NEWLINE/\\n}"\n"; done | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar4[@]}"; i++)); do printf -- "${ar4[$i]//NEWLINE/\n}\n"; done | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar4[@]}"; i++)); do printf "%s\n" ${ar4[$i]//NEWLINE/\\n}; done | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar4[@]}"; i++)); do printf -- "${ar4[$i]//NEWLINE/\n}\n" | ruby -0777 -n -e 'p $_.to_s'; done | nl&lt;br /&gt;for ((i=0; i &lt; "${#ar4[@]}"; i++)); do printf "%s\n" "${ar4[$i]//NEWLINE/\n}" | ruby -0777 -n -e 'p $_.to_s'; done | nl&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 06 Aug 2008 17:16:39 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1592</guid>
      <author>jv (jvscode [[at]] fastmail [[dot]] fm)</author>
    </item>
    <item>
      <title>Switch to the login window from the command line</title>
      <link>http://codesnippets.joyent.com/posts/show/1591</link>
      <description>&lt;code&gt;&lt;br /&gt;# cf. http://www.mactipper.com/2008/07/securely-lock-your-mac-system.html,&lt;br /&gt;# http://www.macosxhints.com/article.php?story=20040724203315798 and&lt;br /&gt;# http://www.apple.com/downloads/macosx/automator/lockdesktop.html&lt;br /&gt;&lt;br /&gt;/System/Library/CoreServices/"Menu Extras"/User.menu/Contents/Resources/CGSession -suspend&lt;br /&gt;&lt;br /&gt;/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID username&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;alias lo='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'&lt;br /&gt;&lt;br /&gt;# &lt;ctrl&gt; + l&lt;br /&gt;help bind&lt;br /&gt;bind -P | grep -i c-l&lt;br /&gt;bind -x '"\C-l"':'/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'&lt;br /&gt;&lt;br /&gt;# &lt;esc&gt; + l&lt;br /&gt;bind -x '"\M-l"':'/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#---------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;open -a 'Keychain Access'&lt;br /&gt;&lt;br /&gt;# go to  Keychain Access &gt; Preferences ... &gt; General &gt; activate "Show Status in Menu Bar" &lt;br /&gt;# now you can use "Lock Screen" via the Keychain Access menu bar item&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 04 Aug 2008 08:02:14 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1591</guid>
      <author>jv (jvscode [[at]] fastmail [[dot]] fm)</author>
    </item>
    <item>
      <title>rmagick gem install on intel mac</title>
      <link>http://codesnippets.joyent.com/posts/show/1590</link>
      <description>sudo env ARCHFLAGS="-arch i386" gem install rmagick</description>
      <pubDate>Sat, 02 Aug 2008 15:31:47 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1590</guid>
      <author>willi (Willi)</author>
    </item>
    <item>
      <title>rmagick test</title>
      <link>http://codesnippets.joyent.com/posts/show/1589</link>
      <description>//  Check if rmagick is installed properly by running gem list. Now we are going to test if rmagick works properly. Create a file called test_rmagick.rb, and copy and paste the code below.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby -wKU&lt;br /&gt;&lt;br /&gt;# Test if rmagick is working properly or not.&lt;br /&gt;# When run, this file creates a image file 'path.gif' in the same directory.&lt;br /&gt;&lt;br /&gt;# the sample code is from http://rmagick.rubyforge.org/portfolio3.html&lt;br /&gt;&lt;br /&gt;require 'rubygems'&lt;br /&gt;require 'rmagick' # Don't use a capital 'R'.&lt;br /&gt;&lt;br /&gt;canvas = Magick::Image.new(240, 300,&lt;br /&gt;              Magick::HatchFill.new('white','lightcyan2'))&lt;br /&gt;gc = Magick::Draw.new&lt;br /&gt;&lt;br /&gt;gc.fill('red')&lt;br /&gt;gc.stroke('blue')&lt;br /&gt;gc.stroke_width(2)&lt;br /&gt;gc.path('M120,150 h-75 a75,75 0 1, 0 75,-75 z')&lt;br /&gt;gc.fill('yellow')&lt;br /&gt;gc.path('M108.5,138.5 v-75 a75,75 0 0,0 -75,75 z')&lt;br /&gt;gc.draw(canvas)&lt;br /&gt;&lt;br /&gt;canvas.write('path.gif')&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 02 Aug 2008 15:00:09 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1589</guid>
      <author>willi (Willi)</author>
    </item>
    <item>
      <title>Beware the trailing slash in mod_proxy_balancer (part 2)</title>
      <link>http://codesnippets.joyent.com/posts/show/1588</link>
      <description>It is a little tricky to prevent mod_proxy_balancer from adding a trailing slash.&lt;br /&gt;&lt;br /&gt;This will redirect /MyService?wsdl to http://example.com:X0000/MyService/&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;    ProxyPass /MyService balancer://playlist_service_balancer&lt;br /&gt;&lt;br /&gt;    &lt;Proxy balancer://playlist_service_balancer&gt;&lt;br /&gt;      BalancerMember http://example.com:10000/MyService&lt;br /&gt;      BalancerMember http://example.com:20000/MyService&lt;br /&gt;&lt;br /&gt;      ProxySet lbmethod=byrequests&lt;br /&gt;    &lt;/Proxy&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This will redirect /MyService?wsdl to http://example.com:X0000/MyService?wsdl&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  ProxyPass /MyService balancer://playlist_service_balancer/MyService&lt;br /&gt;&lt;br /&gt;  &lt;Proxy balancer://playlist_service_balancer&gt;&lt;br /&gt;    BalancerMember http://example.com:10000/&lt;br /&gt;    BalancerMember http://example.com:20000/&lt;br /&gt;&lt;br /&gt;    ProxySet lbmethod=byrequests&lt;br /&gt;  &lt;/Proxy&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;see https://issues.apache.org/bugzilla/show_bug.cgi?id=39203</description>
      <pubDate>Sat, 02 Aug 2008 01:11:20 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1588</guid>
      <author>rainier (Nick)</author>
    </item>
    <item>
      <title>Simple perl script to merge SVN commits from a source branch to the current destination directory with a search string (Bugzilla id, for example) in the comments.</title>
      <link>http://codesnippets.joyent.com/posts/show/1587</link>
      <description>Today i have made my first PERL script!&lt;br /&gt;&lt;br /&gt;For me it is very painful when it arrives the time to merge, into another branch, all the commits that i have done in the &#8220;trunk&#8221;. I have searched a little and did not find anything that could magically solve all my problems. I know that it&#8217;s better to create a separated branch when there are lot&#8217;s of commits, but there are some cases that a super-simple functionality can explode into a big ball of mud.&lt;br /&gt;&lt;br /&gt;Practically the script merge all the commits of a bugzilla id to another branch. If someone knows a standard way to do this; please tell me!&lt;br /&gt;&lt;br /&gt;The script take three inputs:&lt;br /&gt;&lt;br /&gt;   1. The starting revision ID to filter the search.&lt;br /&gt;   2. The SVN address of the source.&lt;br /&gt;   3. The search string to filter the results. Here you put your bugzilla bug id.&lt;br /&gt;&lt;br /&gt;Commands that are executed when you launch the script:&lt;br /&gt;&lt;br /&gt;   1. Go to the directory of the destination branch.&lt;br /&gt;   2. To execute the script simply do:&lt;br /&gt;   3. svn_search_merge.pl 0 https://svn.example.com/main/trunk/ &#8220;1: &#8220;&lt;br /&gt;   4. Note that &#8220;1: &#8221; is the bugzilla bug id. What happens next is:&lt;br /&gt;   5. svn log -r 1:HEAD https://svn.example.com/main/trunk/&lt;br /&gt;   6. With that command we get the log of all commits from the revision 1 to the HEAD. After it&#8217;s just matter of check if the string &#8220;1: &#8221; is inside the log. Then we simply execute:&lt;br /&gt;   7. svn merge -r (ACTUAL_REVISION-1):ACTUAL_REVISION https://svn.example.com/main/trunk/&lt;br /&gt;&lt;br /&gt;Source code of the script:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/perl&lt;br /&gt;&lt;br /&gt;# Simple script to merge commits from a source branch to the current destination directory.&lt;br /&gt;# http://mufumbo.wordpress.com/2008/05/10/simple-script-to-merge-commits-from-a-bugzilla-id/&lt;br /&gt;#&lt;br /&gt;# Example:&lt;br /&gt;# $ cd my-branch-destination/&lt;br /&gt;# $ svn_search_merge.pl 3000 https://svn.example.com/main/trunk/ "bug 673"&lt;br /&gt;# Where 3000 is the starting revision and "bug 673" is the string to match in the comments.&lt;br /&gt;#&lt;br /&gt;use strict;&lt;br /&gt;use warnings;&lt;br /&gt;&lt;br /&gt;my $prev_revision = shift;&lt;br /&gt;my $svnHost = shift;&lt;br /&gt;my $searchStr = shift;&lt;br /&gt;&lt;br /&gt;print "Starting Revision: $prev_revision\n";&lt;br /&gt;print "SVN addr: $svnHost\n";&lt;br /&gt;print "Search pattern: $searchStr\n";&lt;br /&gt;&lt;br /&gt;my $buffer;&lt;br /&gt;$buffer = `svn log -r $prev_revision:HEAD $svnHost`;&lt;br /&gt;my $shouldContinue = "y";&lt;br /&gt;LOGS: foreach my $changelog_entry (split(/----+/m, $buffer)) {&lt;br /&gt;	if($changelog_entry =~ m/($searchStr)/) {&lt;br /&gt;	        #my (undef, $info, undef, $comment) = split(/\n/, $changelog_entry);&lt;br /&gt;	        #next unless $info =~ m/^r/;&lt;br /&gt;&lt;br /&gt;		print "\n--------------------------------------------------";&lt;br /&gt;		print $changelog_entry;&lt;br /&gt;		my $revisionId = substr($changelog_entry, 2, 5);&lt;br /&gt;		$revisionId =~ s/^\s+//;&lt;br /&gt;		$revisionId =~ s/\s+$//;&lt;br /&gt;&lt;br /&gt;		if ($shouldContinue ne 'a') {&lt;br /&gt;			PROMPT: while(1) {&lt;br /&gt;				print "\nShould continue with merge of revision '$revisionId'? (Yes,Always,Skip,Exit): ";&lt;br /&gt;				$shouldContinue = &lt;&gt;;&lt;br /&gt;				chomp($shouldContinue);&lt;br /&gt;&lt;br /&gt;				last PROMPT if $shouldContinue eq 'y';&lt;br /&gt;				last PROMPT if $shouldContinue eq 'a';&lt;br /&gt;				next LOGS if $shouldContinue eq 's';&lt;br /&gt;				die("User requested to stop.") if $shouldContinue eq 'e';&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;		else {&lt;br /&gt;			print "\nAuto merging '$revisionId'\n";&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;		my $pRevisionId = $revisionId-1;&lt;br /&gt;		my $mergeBuffer = `svn merge -r $pRevisionId:$revisionId $svnHost`;&lt;br /&gt;		print $mergeBuffer;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 31 Jul 2008 07:55:13 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1587</guid>
      <author>mufumbo (Rafael Sanches)</author>
    </item>
    <item>
      <title>Delete all _svn folders from Windows command prompt</title>
      <link>http://codesnippets.joyent.com/posts/show/1585</link>
      <description>FOR /R . %f IN (_svn) DO RD /s /q %f</description>
      <pubDate>Tue, 29 Jul 2008 15:42:49 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1585</guid>
      <author>iogoinc (IOGO, INC)</author>
    </item>
    <item>
      <title>Snip - extract a named element from an html file using bash</title>
      <link>http://codesnippets.joyent.com/posts/show/1577</link>
      <description>This is a primitive way of achieving the kind of data extraction that is more commonly associated with true XML for any reasonably modern html file (i.e. that it is well-formed and makes proper use of the id property).  The purpose is mainly to get simple, yet fast and efficient text browsing, especially useful for quick look-ups and the like, e.g. dictionaries, thesauruses (thesauri?), encyclopedias etc. Since the data you're interested in is usually put into a specific element, text browsing is often greatly enhanced by extracting the element in question and discarding the rest. You run the script by specifying an element in the standard css way (element#id) and the file which is to be 'parsed', and the script responds by spitting out the element (and only that element) through html2text which does a really nice job of turning html code into legible console text.&lt;br /&gt;&lt;br /&gt;EDIT: Added a quick check for the presence/absence of the element type in the line (before the grep operations) - greatly increases speed with large elements like #content on wikipedia.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#! /bin/bash&lt;br /&gt;&lt;br /&gt;printhelp () {&lt;br /&gt;echo "snip is a simple bash html cutter that works by extracting a specific element &lt;br /&gt;from an html file and feeding it to html2text. It presupposes wellformed html&lt;br /&gt;and that you know the kind of element you want and it's id.&lt;br /&gt;&lt;br /&gt;Syntax:&lt;br /&gt;snip &lt;element  type&gt;#&lt;element id&gt; &lt;file to parsed&gt;&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;snip div#bodyContent /tmp/index.html&lt;br /&gt;"&lt;br /&gt;exit&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;quitter () {&lt;br /&gt;echo "Element id not found. Quitting."; exit&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[ "$1" = "-h" -o "$1" = "--help" -o "$1" = "" ] &amp;&amp; printhelp&lt;br /&gt;&lt;br /&gt;elementtype="$(echo $1 | cut -d '#' -f 1)"&lt;br /&gt;id="$(echo $1 | cut -d '#' -f 2)"&lt;br /&gt;htmlfile="$2"&lt;br /&gt;thebegin=$(grep -nioE "id=\"$id\"" $htmlfile | cut -d ':' -f 1)&lt;br /&gt;# echo $thebegin&lt;br /&gt;[ -n "$thebegin" ] || quitter&lt;br /&gt;&lt;br /&gt;sed -n ${thebegin}p "$htmlfile" | sed -re "s/^.*id=\"$id\"/&lt;$elementtype id=\"$id\"/g" &gt; /tmp/snipfile&lt;br /&gt;sed -n $(($thebegin+1)),\$p "$htmlfile"  &gt;&gt; /tmp/snipfile&lt;br /&gt;&lt;br /&gt;i=0&lt;br /&gt;element=0&lt;br /&gt;cat /tmp/snipfile | while read line; do&lt;br /&gt;	let i++&lt;br /&gt;	if [[ "$line" =~ "$elementtype" ]]; then&lt;br /&gt;		elementbegincount="$(echo $line | grep -io "&lt;$elementtype" | grep -c .)"&lt;br /&gt;		elementendcount="$(echo $line | grep -io "&lt;/$elementtype" | grep -c .)"&lt;br /&gt;		element=$(($element+$elementbegincount-$elementendcount))&lt;br /&gt;		if [ "$element" -le 0 ]; then&lt;br /&gt;			sed -n 1,${i}p /tmp/snipfile | html2text&lt;br /&gt;			exit&lt;br /&gt;		fi&lt;br /&gt;	fi&lt;br /&gt;done&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;As an example of how the script can be put to use, here's my Wikipedia lookup (the script above is referred to as 'snip' here):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#! /bin/bash&lt;br /&gt;&lt;br /&gt;useragent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071619 Firefox/3.0.1"&lt;br /&gt;if wget -q -U "$useragent" -O /tmp/wpfile "http://en.wikipedia.org/wiki/Special:Search?search=$*"; then&lt;br /&gt;	clear&lt;br /&gt;	echo "Page downloaded..."&lt;br /&gt;	snip div#content /tmp/wpfile | less&lt;br /&gt;else&lt;br /&gt;	echo "No connection, sorry. Please try again."&lt;br /&gt;fi&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Thu, 24 Jul 2008 16:55:53 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1577</guid>
      <author>chochem (chochem)</author>
    </item>
    <item>
      <title>Password request dialog from the command line with AppleScript</title>
      <link>http://codesnippets.joyent.com/posts/show/1573</link>
      <description>&lt;code&gt;&lt;br /&gt;unset -v input&lt;br /&gt;&lt;br /&gt;#input="$(/usr/bin/osascript &lt;&lt;-'__HEREDOC__'&lt;br /&gt;input="$(/usr/bin/osascript 2&gt;/dev/null &lt;&lt;-'__HEREDOC__'&lt;br /&gt;   with timeout of 300 seconds&lt;br /&gt;      tell application "Finder"&lt;br /&gt;--      tell application "System Events"&lt;br /&gt;         activate&lt;br /&gt;         set Input to display dialog "Please enter your password:" \&lt;br /&gt;            with title "Password" \&lt;br /&gt;            with icon caution \&lt;br /&gt;            default answer "" \&lt;br /&gt;            buttons {"Cancel", "OK"} \&lt;br /&gt;            default button 2 \&lt;br /&gt;            with hidden answer \&lt;br /&gt;            giving up after 295&lt;br /&gt;         return text returned of Input as string&lt;br /&gt;      end tell&lt;br /&gt;   end timeout&lt;br /&gt;__HEREDOC__&lt;br /&gt;)"&lt;br /&gt;&lt;br /&gt;printf "%s\n" "${input}"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;open -a 'Script Editor'&lt;br /&gt;&lt;br /&gt;# copy &amp; paste the following snippet into Script Editor &lt;br /&gt;&lt;br /&gt;with timeout of 300 seconds&lt;br /&gt;	tell application "Finder"&lt;br /&gt;		activate&lt;br /&gt;		set Input 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&lt;br /&gt;		return text returned of Input as string&lt;br /&gt;	end tell&lt;br /&gt;end timeout&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;#---------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;unset -v input name&lt;br /&gt;#export name="$(/usr/bin/logname)"&lt;br /&gt;export name="$(/usr/bin/whoami)"&lt;br /&gt;&lt;br /&gt;input="$(/usr/bin/osascript 2&gt;/dev/null &lt;&lt;-__HEREDOC__&lt;br /&gt;   with timeout of 300 seconds&lt;br /&gt;      tell application "Finder"&lt;br /&gt;--      tell application "System Events"&lt;br /&gt;         activate&lt;br /&gt;         set my_name to "${name}"&lt;br /&gt;         set my_pass to display dialog "Enter password for " &amp; quoted form of my_name \&lt;br /&gt;            with title "Login Window" \&lt;br /&gt;            with icon note \&lt;br /&gt;            default answer "" \&lt;br /&gt;            buttons {"Cancel", "OK"} \&lt;br /&gt;            default button 2 \&lt;br /&gt;            with hidden answer \&lt;br /&gt;            giving up after 295&lt;br /&gt;            return text returned of my_pass as string&lt;br /&gt;      end tell&lt;br /&gt;   end timeout&lt;br /&gt;__HEREDOC__&lt;br /&gt;)"&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;printf "%s\n" "${input}"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 23 Jul 2008 17:21:28 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1573</guid>
      <author>jv (jvscode [[at]] fastmail [[dot]] fm)</author>
    </item>
    <item>
      <title>Login window from the command line with Pashua</title>
      <link>http://codesnippets.joyent.com/posts/show/1570</link>
      <description>&lt;code&gt;&lt;br /&gt;export PATH="/usr/bin:/bin:/usr/sbin:/sbin"&lt;br /&gt;export IFS=$' \t\n'&lt;br /&gt;&lt;br /&gt;mkdir -p ~/Applications&lt;br /&gt;&lt;br /&gt;ls -ld ~/Applications&lt;br /&gt;stat -x ~/Applications&lt;br /&gt;&lt;br /&gt;cd ~/Applications&lt;br /&gt;curl -L -O http://www.bluem.net/files/Pashua.dmg&lt;br /&gt;hdiutil mount Pashua.dmg&lt;br /&gt;cp -R /Volumes/Pashua ~/Applications/Pashua&lt;br /&gt;hdiutil unmount /Volumes/Pashua&lt;br /&gt;&lt;br /&gt;cd ~/Applications/Pashua/Examples&lt;br /&gt;cp -p example.sh example.sh.orig   # backup&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# some in-place text editing commands to modify ~/Applications/Pashua/Examples/example.sh&lt;br /&gt;# cf. http://bash-hackers.org/wiki/doku.php?id=howto:edit-ed&lt;br /&gt;&lt;br /&gt;export FILE="${HOME}/Applications/Pashua/Examples/example.sh"&lt;br /&gt;&lt;br /&gt;# replace #!/bin/sh with #!/bin/bash&lt;br /&gt;/bin/ed -s "${FILE}" &lt;&lt;&lt; $'1,1s|bin/sh|bin/bash|\nw'&lt;br /&gt;&lt;br /&gt;# to set the encoding to UTF-8 we add: set -- test utf8&lt;br /&gt;/bin/ed -s "${FILE}" &lt;&lt;&lt; $',s|\(.*Manage encoding.*\)|set -- test utf8 # set $2 to "utf8"\\\n\\\n\\1|\nw'&lt;br /&gt;&lt;br /&gt;# delete all lines after first regex match /conf="/&lt;br /&gt;/bin/ed -s "${FILE}" &lt;&lt;&lt; $'/conf="/;$d\nw'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# add the following configuration&lt;br /&gt;&lt;br /&gt;/bin/cat &gt;&gt; "${FILE}" &lt;&lt;-'EOF'&lt;br /&gt;&lt;br /&gt;conf="&lt;br /&gt;&lt;br /&gt;# Set transparency: 0 is transparent, 1 is opaque&lt;br /&gt;*.transparency=0.95&lt;br /&gt;&lt;br /&gt;# Set window title&lt;br /&gt;*.title = Login Window&lt;br /&gt;&lt;br /&gt;*.x = 550&lt;br /&gt;*.y = 300&lt;br /&gt;*.autoclosetime = 300&lt;br /&gt;&lt;br /&gt;name.type = textfield&lt;br /&gt;name.label = Please enter your name:&lt;br /&gt;name.width = 280&lt;br /&gt;name.x = 0&lt;br /&gt;name.y = 110&lt;br /&gt;&lt;br /&gt;password.type = password&lt;br /&gt;password.label = Please enter your password:&lt;br /&gt;password.width = 280&lt;br /&gt;password.x = 0          &lt;br /&gt;password.y = 45        &lt;br /&gt;&lt;br /&gt;# Add a cancel button with default label&lt;br /&gt;cb.type = cancelbutton&lt;br /&gt;&lt;br /&gt;";   # end conf&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;pashua_run "$conf"&lt;br /&gt;#pashua_run "$conf" "utf8"   # alternative to "set -- test utf8" above&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if [[ ${cb} -ne 0 ]]; then echo 'Login cancelled!'; exit 1; fi&lt;br /&gt;&lt;br /&gt;printf "%s\n" "name = ${name}"&lt;br /&gt;&lt;br /&gt;printf "%s\n" "${name}" | ruby -n -e 'p $_.to_s'&lt;br /&gt;&lt;br /&gt;# the following command requires #!/bin/bash&lt;br /&gt;# cf. http://www.lugbz.org/pipermail/lugbz-list/2006-December/016360.html&lt;br /&gt;/bin/ed -s &lt;((printf "%s\n" "${name}")) &lt;&lt;&lt; $',l'   &lt;br /&gt;&lt;br /&gt;printf "%s\n" "password = ${password}"&lt;br /&gt;printf "%s\n" "cb = ${cb}"&lt;br /&gt;&lt;br /&gt;#printf "%s\n" "${password}" | /usr/bin/sudo -S /bin/ls | /usr/bin/head -n 5&lt;br /&gt;&lt;br /&gt;/sbin/md5 -qs "${password}"&lt;br /&gt;&lt;br /&gt;EOF&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# run the script&lt;br /&gt;~/Applications/Pashua/Examples/example.sh&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 22 Jul 2008 21:45:52 GMT</pubDate>
      <guid>http://codesnippets.joyent.com/posts/show/1570</guid>
      <author>jv (jvscode [[at]] fastmail [[dot]] fm)</author>
    </item>
  </channel>
</rss>
