Bash script to rename files given a text file with new filenames

Yesterday I found myself needing to rename a bunch of files given a text file with the new names, so I had to use some of my (few) bash skills. I’m sure I could have done it in fewer lines, but the bash script below did the job.


# v1.1
# ./ text.txt *.dat

if [ "$#" == "0" ]; then
    echo "./ names.txt \"*.dat\""
    exit 1


# read file line by line, store in array with leading number and .mp3 postfix
while read line; do
	fileNum=`printf "%02d" $((index+1))`
	names[index]="$fileNum. $line.dat" # Custom rename format
done < $namefile


if [ "$#" -ne "$namecount" ]; then
	echo "Number of files ($#) doesn't match number of lines in $namefile ($namecount)"
	exit 1

# rename input files to match lines in the array
for file in "${files[@]}" ; do
	file=$(printf "%q" "$file")
	newfile=$(printf "%q" "${names[index]}")
	eval "mv $file $newfile"
Posted in Mac, Work | Tagged , , | Leave a comment

ComHem TivoToGo krashar på iPad – lösning

This one is in Swedish, but if your TiVo app crashes when used to control your TiVo box – use Google translate to read the text below.

Sedan en tid tillbaka har TivoToGo börjaat krasha direkt vid start på min iPad. Efter ett fruktlöst samtal med ComHems support bestämde jag mig för att spåra ner problemet.

Det första jag märkte var att appen bara krashade när iPaden är ansluten till samma wifi som Tivo-boxen, om jag stängde av wifi på iPaden och startade på 3G så funkade appen. Jag kunde dock givetvis inte styra boxen vilket är en del av appens poäng.

Så appen och boxen pratar på något sätt, antingen direkt eller via ComHem. Jag bestämde mig för att ta reda på det och kickade igång WireShark. För att inte bråka med inställningarna för krypteringsnycklar tog jag bort lösenordet på min wifi access point… och VIPS så började appen funka och styra boxen! Märkligt! Jag satte tillbaka samma lösenord – crash igen. Tog bort lösenordet – funkar! Satte ett nytt lösenord – FUNKAR! Wtf?

Har inte orkat kolla noggrant men det såg inte heller ut som att det gick trafik mellan boxen och appen, kommunikationen verkar ske via ComHem. Använder de möjligen krypteringsnycklarna för det wifi iPaden är på för att identifiera ens nät? ComHem – kommentar? =)

Hur som helst, jag är för lat för att undersöka detta vidare, enda uppsidan skulle ju vara att kunna styra TiVon från ett annat LAN, inget jag är jätteintresserad av. Kontentan är:


Posted in iOS | Leave a comment

Karabiner Num Lock to Eject

Put this in your private.xml to remap Num Lock to Eject on your Mac running OSX

<?xml version="1.0"?>
    <name>Map NumLock to Eject</name>
    <autogen>--KeyToKey-- KeyCode::PC_KEYPAD_NUMLOCK, KeyCode::VK_CONSUMERKEY_EJECT</autogen>
Posted in Mac | Leave a comment

Screen Lock Disable Timer in Google Play!

Another Android app released to the Google Play Store!

Screen Lock Disable Timer allows you to disable your swipe or pattern screen lock (aka keyguard) temporarily. Useful if you need to turn your screen on and off repeatedly for a while and don’t want to unlock each time!


Posted in Android | Leave a comment

Restoring SharePoint 2010 content DB

To do this:
1. Stop the SharePoint 2010 Timer and SharePoint 2010 Tracing services
2. Kill any IIS processes:

 Get-Process -Name w3wp | Stop-Process

3. Restore

Posted in Uncategorized, Work | Tagged | Leave a comment

Fix for AuthManager(CommerceServer): Error reading Commerce Server administration database

The below exception is easily remedied by removing all entries that relate to Commerce Server authentication module from your web.config. You are probably not using that module. 🙂

[COMException (0x800a0cc1): AuthManager(CommerceServer): Error reading Commerce Server administration database. Check the AddressKeyName setting in the CSApp.ini file for the site and ensure that it refers to the name of a Commerce Server application that exists for the site. Site name: 'MySite' Application name: 'MySite' Auth resource property: 's_SecureHostname' HRESULT: 0x800A0CC1]

Posted in Work | Tagged | Leave a comment

Headset Menu for Android hits the Play Store

I now have an app in the Play Store for Android. It’s called Headset Menu and provides easy access to your music apps!

What does it do?

This is shown in your notification area when you connect your headset to your phone. Easy to pick the right app!


And this is the configuration screen:

Main screen

Check it out on Google Play!

Posted in Uncategorized | Tagged , | 1 Comment

SharePoint 2007 listitem manager

For a while now I’ve tried to find a tool that would allow me to export a SharePoint 2007 list to Excel, modify the data and then import it to another system. In my case I wanted to move data between our many testing environments and modify it easily and in bulk.

Having failed to find a good solution for this I’ve created a tool. It’s published on GitHub and named SharePoint listitem manager. The current version is v0.11 which does the basics (export and import), but I hope to expand and improve the tool as time goes.

At the moment I don’t provide any binaries to download. Feel free to clone the repo and build the solution yourself. The tool is totally untested so I don’t want to release it as a binary quite yet.

Posted in Work | Tagged , , | Leave a comment

“No authority could be contacted for authentication” in SharePoint farm

Just ran into this when trying to access SharePoint 3.0 Central Administration on for my MOSS farm.

Turns out the AD somehow got corrupted when I restarted the servers in the farm. The solution was to remove the servers from the domain, delete the computer accounts (using the dsa.msc MMC plugin) and then re-add the servers and restart them…

Great way to spend a couple of night hours! 🙂

Posted in Work | Tagged , | Leave a comment

Getting current page URL (or it’s parts) in C#

Here is an easy reference for how to get different parts of an URL in C#.

I’ve color-coded the example URL below for easier matching with the values of the properties of the HttpRequest.

URL used for this example:

Value of HttpContext.Current.Request.Url.Host

Value of HttpContext.Current.Request.Url.Authority

Value of HttpContext.Current.Request.Url.AbsolutePath

Value of HttpContext.Current.Request.ApplicationPath

Value of HttpContext.Current.Request.Url.AbsoluteUri

Value of HttpContext.Current.Request.RawUrl

Value of HttpContext.Current.Request.Url.PathAndQuery

Posted in Work | Tagged , , , , , | 2 Comments