Tuesday, November 2, 2010

Get rid of Office 2011's First Run Wizard

I made a similar script like this for Office 2008, but Microsoft changed some things in Office 2011 and how it determines if First Run Wizard is run.
It seems like the Office apps looks at three files and certain settings in them, these files are:

~/Library/Preferences/com.microsoft.office.plist
~/Library/Preferences/com.microsoft.autoupdate2.plist
~/Library/Preferences/com.microsoft.error_reporting

The file "com.microsoft.office.plist" must contain:
- The key "14\FirstRun\SetupComplete" with value "1" (-int)

The file "com.microsoft.autoupdate2.plist" must contain:
- The key "HowToCheck" with value "Manual" (-string) (if you don't want it to check automatically)
- The key "LastUpdate" with value "2001-01-01T00:00:00Z" (-date)

The file "com.microsoft.error_reporting must contain:
- The key "SQMReportsEnabled" with value "False" (-bool)
- The key "ShipAssertEnabled" with value "False" (-bool)

And as an optional thing, in the script below, I added a function that sets the user's name in "com.microsoft.office.plist".

Pardon me for the lack of comments in the script below, but I think you understand it :)

Provided "as is"...

#!/bin/bash

# Loginhook to get rid of Office First run.
# This version is for Office 2011
# Updated 101102 by Marcus Jaensson

##### NOTES ABOUT FILE PERMISSIONS ######
# Setting rights to 777 as chown does not seem to work as expected in a loginhook
# It seems that Office sets the correct owner on the files when launching an Office-app
# Really no secrets in these files anyway...



# Install this:
# 1. Copy this to /Library/Scripts/loginhook.sh
# 2. Set owner to root and chmod 755
# 3. sudo defaults write com.apple.loginwindow LoginHook /Library/Scripts/loginhook.sh

LOGF="/tmp/loginhook.log"

OFFICEPREF="/Users/$1/Library/Preferences/com.microsoft.office.plist"
OFFICEDOMAIN="/Users/$1/Library/Preferences/com.microsoft.office"

AUPREF="/Users/$1/Library/Preferences/com.microsoft.autoupdate2.plist"
AUDOMAIN="/Users/$1/Library/Preferences/com.microsoft.autoupdate2"

ERPREF="/Users/$1/Library/Preferences/com.microsoft.error_reporting.plist"
ERDOMAIN="/Users/$1/Library/Preferences/com.microsoft.error_reporting"


echo "##### Beginning Log #####" >> $LOGF
echo `date "+%y%m%d %H.%M"` >> $LOGF
echo "User: $1" >> $LOGF


# Create files and values com.microsoft.office.plist
if [ -f "$OFFICEPREF" ]
then
echo "com.microsoft.office.plist exists." >> $LOGF
echo "Checking if 14\\FirstRun\\SetupComplete has value 1" >> $LOGF
SETUPSTATUS=$(defaults read "$OFFICEDOMAIN" "14\\FirstRun\\SetupComplete")
if [ $SETUPSTATUS = 1 ]
then
echo "SetupComplete is set to 1. Nothing to do" >> $LOGF
else
echo "Setting SetupComplete to 1" >> $LOGF
defaults write "$OFFICEDOMAIN" "14\\FirstRun\\SetupComplete" -int 1
chmod -f 777 "$OFFICEPREF"
fi
else
echo "com.microsoft.office.plist does not exist. Creating it and setting SetupComplete to 1" >> $LOGF
defaults write "$OFFICEDOMAIN" "14\\FirstRun\\SetupComplete" -int 1
chmod -f 777 "$OFFICEPREF"
fi

# Create fields and values com.microsoft.autoupdate2.plist
if [ -f "$AUPREF" ]
then
echo "com.microsoft.autoupdate2.plist exists." >> $LOGF
echo "Checking if HowToCheck has value Manual" >> $LOGF
HOWTOCHECK=$(defaults read "$AUDOMAIN" "HowToCheck")
LASTUPDATE=$(defaults read "$AUDOMAIN" "LastUpdate")
if [ $HOWTOCHECK = "Manual" ]
then
echo "HowToCheck is set to Manual. Nothing to do" >> $LOGF
else
echo "Setting HowToCheck to Manual" >> $LOGF
defaults write "$AUDOMAIN" "HowToCheck" -string "Manual"
chmod -f 777 "$AUPREF"
fi
if [ -z "$LASTUPDATE" ]
then
echo "LastUpdate is empty, populating"
defaults write "$AUDOMAIN" "LastUpdate" -date "2001-01-01T00:00:00Z"
else
echo "LastUpdate exists"
fi
else
echo "com.microsoft.autoupdate2.plist does not exist. Creating it and setting HowToCheck and LastUpdate to Manual" >> $LOGF
defaults write "$AUDOMAIN" "HowToCheck" -string "Manual"
defaults write "$AUDOMAIN" "LastUpdate" -date "2001-01-01T00:00:00Z"
chmod -f 777 "$AUPREF"
fi

# Create fields and values com.microsoft.error_reporting.plist
if [ -f "$ERPREF" ]
then
echo "com.microsoft.error_reporting.plist exists." >> $LOGF
echo "Checking if SQMReportsEnabled has value False" >> $LOGF
SQMREPORTS=$(defaults read "$ERDOMAIN" "SQMReportsEnabled")
SHIPASSERT=$(defaults read "$ERDOMAIN" "ShipAssertEnabled")
if [ $SQMREPORTS = "0" ]
then
echo "SQMReportsEnabled is set to False. Nothing to do" >> $LOGF
else
echo "Setting SQMReportsEnabled to False" >> $LOGF
defaults write "$ERDOMAIN" "SQMReportsEnabled" -bool False
chmod -f 777 "$ERPREF"
fi
if [ $SHIPASSERT = "0" ]
then
echo "ShipAssertEnabled is set to False. Nothing to do" >> $LOGF
else
echo "Setting ShipAssertEnabled to False" >> $LOGF
defaults write "$ERDOMAIN" "ShipAssertEnabled" -bool False
chmod -f 777 "$ERPREF"
fi
else
echo "com.microsoft.error_reporting.plist does not exist. Creating it and setting SQMReportsEnabled and ShipAssertEnabled to False" >> $LOGF
defaults write "$ERDOMAIN" "SQMReportsEnabled" -bool False
defaults write "$ERDOMAIN" "ShipAssertEnabled" -bool False
chmod -f 777 "$ERPREF"
fi


# Set name
REALNAME=$(dscl . -read /Users/$1 RealName | grep -v RealName | sed 's/^[ ]*//')
echo "RealName is $REALNAME" >> $LOGF
REALNAMESTATUS=$(defaults read "$OFFICEDOMAIN" "14\\UserInfo\\UserName")
echo "RealName Status is $REALNAMESTATUS" >> $LOGF
if [ -z "$REALNAMESTATUS" ]
then
echo "Setting realname" >> $LOGF
defaults write "$OFFICEDOMAIN" "14\\UserInfo\\UserName" -string "$REALNAME"
chmod -f 777 "$OFFICEPREF"
else
echo "REALNAME is already set" >> $LOGF
fi

echo -e "---------- Ending Log ----------\n" >> $LOGF

exit 0

Monday, October 25, 2010

Change default keyboard layout for loginwindow

We discovered that a system restore image we used to deploy new Macs with had the wrong keyboard layout at the loginwindow. If you change the keyboard layout in the Accounts PrefPane, it just affects the currently logged in user.
Apples solution to this is either to reinstall Mac OS X or select to show the input menu in the loginwindow, this is two solutions that I can't accept, so I started digging and found a solution!

The settings are stored in /Library/Preferences/com.apple.HIToolbox.plist and changing these solved my problem.

Here is quick and dirty script to change the default keyboard layout to Swedish:


#!/bin/bash

# This will set default keyboard language to Swedish.

# Path to plist file
PLISTDOMAIN="/Library/Preferences/com.apple.HIToolbox.plist"

# Path to PlistBuddy
PB="/usr/libexec/PlistBuddy"

"$PB" -c "set :AppleDefaultAsciiInputSource:KeyboardLayout\ ID 7" "$PLISTDOMAIN"
"$PB" -c "set :AppleDefaultAsciiInputSource:KeyboardLayout\ Name Swedish\ -\ Pro" "$PLISTDOMAIN"
"$PB" -c "set :AppleCurrentKeyboardLayoutInputSourceID com.apple.keylayout.Swedish-Pro" "$PLISTDOMAIN"
"$PB" -c "set :AppleEnabledInputSources:0:KeyboardLayout\ ID 7" "$PLISTDOMAIN"
"$PB" -c "set :AppleEnabledInputSources:0:KeyboardLayout\ Name Swedish\ -\ Pro" "$PLISTDOMAIN"

exit 0

Tuesday, October 19, 2010

Create mobile account for two different users with the same name fails

We discovered this today, and we haven't found any information about it anywhere, so...

If you have a mac bound to an Active Directory where there are users with the same name but different usernames, you may see that certain users cannot login to the mac. This happens when you have "Create mobile account at login" activated and a user tries to login who has the same name as a previously logged in user.

What is going wrong then? I don't know exactly, besides that it's the "RecordName" key that is the problem. There cannot be two users in the local database that has a value in RecordName matching any other user's value in RecordName.

If you change the value to something else on the first user, the second user can login.

Delete the value:
sudo dscl . delete /Users/uname1 RecordName "John Doe"

Append a new value:
sudo dscl . append /Users/uname1 RecordName "John Marc Doe"

Or simply change:
sudo dscl . change /Users/uname1 RecordName "John Doe" "John Marc Doe"

UPDATE 2010-10-20
I made a bugreport to Apple regarding this yesterday and got a response that they need logs. I will upload the logs today to Apple and then we'll see what they have to say about it...

UPDATE 2010-10-25
Apple says this is expected behavior. I have replied that I disagree.

Wednesday, September 22, 2010

Convert movies to iPhone friendly format with ffmpeg on a Mac

I wanted to make a bash script that parsed a given directory for movie files and then made them into an iPhone friendly format. In this script I use HandBrakeCLI and ffmpeg.

HandBrakeCLI is a no-brainer to install, just download the binary and run it, but ffmpeg is a bit harder to get working, so here are a brief and "technical" instruction on how I succeeded. Apple Developer Tools is required!

1. mkdir ~/source
2. cd ~/source

3. cvs -d:pserver:anonymous@lame.cvs.sourceforge.net:/cvsroot/lame login (press enter when asked for passwd)
4. cvs -z3 -d:pserver:anonymous@lame.cvs.sourceforge.net:/cvsroot/lame co -P lame
5. cd lame
6. ./configure
7. make
8. sudo make install

9. cd ~/source
10. cvs -d:pserver:anonymous@faac.cvs.sourceforge.net:/cvsroot/faac login
11. cvs -z3 -d:pserver:anonymous@faac.cvs.sourceforge.net:/cvsroot/faac co -P faac
12. cd faac
13. ./configure
14. make
15. sudo make install

16. cd ~/source
17. svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
18. cd ffmpeg
19. ./configure --enable-libmp3lame --enable-shared --disable-mmx --arch=x86_64 --enable-libfaac --enable-gpl --enable-nonfree --enable-avfilter --enable-postproc
20. make
21. sudo make install


And now, when you're done, you can convert movies to mp4 that is 480px wide and keeping the aspect ratio. This is what I use, found bits here and there and put it together to this:

ffmpeg -i INPUT.avi -acodec libfaac -ac 2 -vcodec mpeg4 -vf "scale=480:-1" -b 1000k -ab 128k -coder 1 -flags +aic+cbp+loop+mv4+naq -trellis 1 OUTPUT.mp4

I'm using ffmpeg SVN-r25157, Lame 3.98.4 and faac 1.28 on Mac OS X 10.6.4. If you download and compile the standard ffmpeg 0.6, the "-vf "scale=480:-1" bit will not work. So download the latest through cvs.

This is more or less a rip off of the instruction at stephenjungels.com. In the latest svn of ffmpeg, there is no support for faad, so I left that bit out.

This instruction is available "as is". I will not answer any questions about "How do I do this and that?"

Friday, August 20, 2010

If Boot Camp drivers fails to install

Had this problem yesterday with a new iMac (iMac10,1).

I had an old Windows XP SP3 image with all the applications etc I wanted in Windows. I applied the image to a Boot Camp partition, booted Windows without any problems.

Now I wanted to install the Boot Camp drivers from the Snow Leopard DVD, I launched the installation, but it failed immediately with a message saying something like "a problem occurred, please try again later".

The event log said "msiinstaller error code 11708", which gave me nothing.
Then I launched the BootCamp.msi (in /Boot Camp/Drivers/Apple) with "msiexec /i BootCamp.msi /l* c:\bc.log". In the log file I found that a function called GETINTELGRXID failed with exit code 3.
I think this is supposed to get which kind of Intel graphics card it is in the machine, but since it's an Nvidia card in this iMac I thought it didn't matter if that function ran or not.

So next thing to do was editing the msi with Orca and delete all entries that contained "GETINTELGRXID" (I think I found it in two places). When that was done, I just saved the msi and launched it with the command above, and it worked! Now I have an iMac that have a fully working Boot Camp install!

Thursday, June 3, 2010

Task Sequnce to install App-V 4.6 and remove older App-V and Softgrid versions

This is a sequence I created for installing the App-V 4.6 client. At our university we have many different Softgrid/App-V installations, so I had to make this TS with a lot of different conditions for each step. Hope this will help someone :)

The PDF is just an overview of the task sequence, it requires some knowledge and packages to be created already, you must also have the MSIs for all the older versions you want to uninstall (to be able to create conditions).

App-V 4.6 TS.pdf

Provided "as is"...

Reassign Site Code in SCCM client

Found this yesterday... If you want to trigger an automatic site code discovery in the Config Manager client, you can distribute this vbscript as an assigned program:

Set smsclient=CreateObject("Microsoft.SMS.Client") 
smsclient.ReAssignSite()

Simple? Yes :) But it took me a while to find this, so I wanted to share it!