Command Line

Capture HTTP requests from tcp dump

Add the following block to your ~/.bashrc, replacing interface_name_like_en1 by your network interface name.

eg: On mac, en0 usually is your ethernet adapter and en1 is your wireless. Get a list of your interfaces by running ifconfig -aum inet.

alias webdump=$'sudo tcpdump -i interface_name_like_en1 -s 1500 -A "tcp port 80" |
              /opt/local/bin/perl -e \'my$path="";while(<>){$path=$1
              if($_=~/GET (\S+)/);if($_=~/Host: (\S+)/&&!($path eq""))
              {print"http://$1$path\n";}}\''

Just run webdump, and anytime your computer makes an HTTP request on port 80, it will be printed out.

You can now see what all those plugins are downloading :)

Please note that while this script has never failed me, it relies on the traditional IT methodology of lots-of-chance.

In extenso: There is no garantee whatsoever that this captures all HTTP requests.
Though it does seem to get most.

Why its incomplete: it just looks for GET and Host: line prefixes. It makes no attempt to reconstruct and parse HTTP streams. The following errors will prevent detection or make false reports (though as I said, in practice, it works like a charm):

  • If a separate TCP packet is used for the GET and Host: headers, they can be out of sequence
  • If an HTTP download or other header contains what looks like an HTTP header

Use passwords from Keychain in scripts and command line tools

Mac OS X only

Here is a piece of bash script to source:

function get_keychain_password () {
    if pass=`security find-internet-password -ga "$1" 2>&1 >/dev/null`; then
        without_prefix="${pass#password: \"}"
        echo "${without_prefix%\"}"
    else
        echo "Error: Password not found for account '$1'." >&2
        return -1
    fi
}

Add a password for the service you will use: How to add a KeyChain password

Then simply run

echo The pass is: "$(get_keychain_password "vnc @ example.com")"

Some security concerns

  • Your password is accessible to anyone who can run that function
  • Your password will be visible in parameter lists of processes, so use an environment variable instead, such as
THE_VAR_YOUR_TOOL_USES_TO_GET_THE_PASSWORD="$(get_keychain_password "vnc @ example.com")" tool

Open In Browser button

This small modification makes the “Insert link to active page in Safari” from chat windows in adium support Opera and suggest links from it if you have it open.

You don’t even need to close and restart Adium. Changes are instantaneous.

on run
	substitute("Please pick the browser and link to insert:")
end run
on substitute(severalBrowsersPrompt)
	set candidates to {}
	set labelledcandidates to {}
	set candidateURLs to {}
	tell application "System Events"
		if ((application processes whose (name is equal to "Opera")) count) is greater than 0 then
			tell application "Opera"
				if (number of documents) is greater than 0 then
					set the end of labelledcandidates to "Opera: " & (name of front document)
					set the end of candidates to (name of front document)
					set the end of candidateURLs to (URL of front document)
				end if
			end tell
		end if
		
		if ((application processes whose (name is equal to "Safari")) count) is greater than 0 then
			tell application "Safari"
				if (count of documents) is greater than 0 then
					set the end of labelledcandidates to "Safari: " & (name of front document)
					set the end of candidates to (name of front document)
					set the end of candidateURLs to URL of front document
				end if
			end tell
		end if
		if ((application processes whose (name is equal to "OmniWeb")) count) is greater than 0 then
			tell application "OmniWeb 5.8sp1.app"
				if (count of every «class Owbc») is greater than 0 then
					set the end of labelledcandidates to "OmniWeb: " & (name of front «class Owbc»)
					set the end of candidates to (name of front «class Owbc»)
					set the end of candidateURLs to «class curl» of front «class Owbc»
				end if
			end tell
		end if
		if ((application processes whose (name is equal to "Camino")) count) is greater than 0 then
			using terms from application "Camino.app"
				tell application "Camino.app"
					if version  1.6 then
						if (count of every window) is greater than 0 then
							set the end of labelledcandidates to "Camino: " & (name of front window)
							set the end of candidateURLs to the URL of the «class pCTb» of front «class BWin»
							set the end of candidates to name of front window
						end if
					end if
					if version  1.0 and version < 1.6 then
						if (count of every window) is greater than 0 then
							set the end of labelledcandidates to "Camino: " & (name of front window)
							set the end of candidateURLs to the «class curl» of front window
							set the end of candidates to name of front window
						end if
					end if
				end tell
			end using terms from
		end if
		if ((application processes whose (name is equal to "firefox-bin")) count) is greater than 0 then
			tell application "Firefox"
				if (count of every window) is greater than 0 then
					set firefoxProperties to properties of front window as list
					set the end of labelledcandidates to "Firefox: " & (item 2 of firefoxProperties)
					set the end of candidateURLs to item 3 of firefoxProperties
					set page_title to item 2 of firefoxProperties
				end if
			end tell
			if page_title = "" then
				set page_title to "(Untitled page)"
			end if
			set the end of candidates to page_title
		end if
		if ((application processes whose (name is equal to "NetNewsWire")) count) is greater than 0 then
			tell application "NetNewsWire.app"
				if («class SeTb») is greater than 0 then
					set nnwselT to «class SeTb» -- the news items tab is not present in the lists of titles and tabs, so we have to bump this
					-- gotta prefetch these
					set nnwtitles to «class TbTl»
					set nnwurls to «class TbUr»
					set the end of labelledcandidates to "NetNewsWire: " & (item nnwselT of nnwtitles)
					set the end of candidates to (item nnwselT of nnwtitles)
					set the end of candidateURLs to (item nnwselT of nnwurls)
				end if
			end tell
		end if
		if ((application processes whose (name is equal to "Shiira")) count) is greater than 0 then
			tell application "Shiira.app"
				if (count documents) > 0 then
					set the_doc to document 1
					set the end of labelledcandidates to "Shiira: " & name of the_doc
					set the end of candidates to name of the_doc
					set the end of candidateURLs to URL of the_doc
				end if
			end tell
		end if
		if ((count of labelledcandidates) is greater than 1) then
			set theChosen to {}
			try
				tell application "Adium"
					set theChosen to (choose from list labelledcandidates with prompt severalBrowsersPrompt)
				end tell
			on error
				return ""
			end try
			if theChosen is not equal to {} then
				repeat with chosen in theChosen
					set i to 1
					repeat with aName in labelledcandidates
						if aName & "" is equal to chosen & "" then
							return "<HTML><A HREF=\"" & (item i of candidateURLs) & "\">" & (item i of candidates) & "</A></HTML>"
						end if
						set i to i + 1
					end repeat
				end repeat
			end if
		else if ((count of labelledcandidates) is 1) then
			return "<HTML><A HREF=\"" & (item 1 of candidateURLs) & "\">" & (item 1 of candidates) & "</A></HTML>"
		else
			return ""
		end if
	end tell
end substitute