Archives for posts with tag: osx

On a Mac change directories to:

/Applications/VirtualBox.app/MacOS

vim portfw.rb

#!/usr/bin/ruby
if(ARGV.size < 4) 
	print "Ussage: ruby portfw.rb    \n"  
	exit()
end
print "Adding Portforwarding from #{ARGV[2]} to #{ARGV[3]} named (#{ARGV[1]} on VBOX:#{ARGV[0]}\n"

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/HostPort" #{ARGV[2]}`

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/GuestPort" #{ARGV[3]}`

`./VBoxManage setextradata "#{ARGV[0]}" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/#{ARGV[1]}/Protocol" TCP`

This simple script will make it easy to port forward local ports to a NATed virtualbox.

I recommend adding local aliases for ssh and scp

i.e.

# ~/.bashrc
alias sshl='ssh -p 2222'
alias scpl='scp -p 2222'

so you can just type

sshl localhost
Advertisements

I don’t feel like rehashing the hours I spent today trying to get various methods of taking command line screen shots of web-pages to work, but I’ll pull out a few useful pointers here.

There are 2 ways of doing this for free. (That is, if you value your time at $0 an hour)

First: khtml2png

http://khtml2png.sourceforge.net

khtml2png2 can be installed via a debian package, and runs on any variant of linux, as long as you have KDE installed. I didn’t, and thus spent a long time downloading KDE. It uses Konquerer to render the webpages, and Konquerer will often prompt for user input when something is wrong (i.e. — a plugin is missing (FLASH), or the web site wants access to your cookies.) It also was incredibly slow on my relatively fast desktop machine. However, it does the job — alright, and fits the price — free.

Second: webkit2png

Unfortunately, I was determined to make this process a little bit faster, and spent about 4 hours trying to get http://www.paulhammond.org/webkit2png/ to work. Webkit2png will run on OSX and takes screenshots using WebKit. It is fast, and a pain in the ass to install if you are unlucky. You’ll need Python, and the PyObjC wrappers. It was trivial for me to setup the wrappers from http://pyobjc.sourceforge.net/. The whole process should be pretty straightforward, install PyObj, and grab the Python code from the above website, no problem. Of course on my computer WebKit the header files the PyObjC setup.py wanted could not be found, and because of this the PyObj was not generating some of the files that PyObjC needed to run, “_WebKit_Str.inc” in particular. I tried a few tricks to make the setup.py find these header files, and managed to completely screw up my webkit install. Long story short, the script that generates stub files for PYOBJC ONLY looks in /System/Library/Frameworks/ no matter what you specify in the setup.py, and doesn’t even look in /Library/Frameworks even though it is listed in the default setup.py.

For PYOBJC to install correctly, you must have a directory called WebKit.framework in /System/Library/Frameworks, and it MUST have a Headers directory inside of it. And these headers must match the binary version of the WebKit library. I.e. you should have a directory structure that looks like:

bcx-mbp:/System/Library/Frameworks/WebKit.framework root# ls -l
total 24
lrwxr-xr-x    1 root  wheel    27 Jun  3 23:29 Frameworks -> Versions/Current/Frameworks
drwxr-xr-x   42 root  wheel  1428 Jun  3 23:40 Headers
lrwxr-xr-x    1 root  wheel    26 Jun  3 23:29 Resources -> Versions/Current/Resources
drwxr-xr-x    4 root  wheel   136 Jun  3 23:21 Versions
lrwxr-xr-x    1 root  wheel    23 Jun  3 23:29 WebKit -> Versions/Current/WebKit
bcx-mbp:/System/Library/Frameworks/WebKit.framework root#

The problem that I faced, and caused me to waste so much time was that I was missing the Headers directory inside of /System/Library/Frameworks/WebKit.framework. To solve this problem you can try doing a find -name WebKit.h and copying the Headers directory containing this file into your WebKit.framework directory. In my case I had another copy of the WebKit headers at: /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/WebKit.framework . Copying the headers directory from the above directory did the trick.

Now I left out a lot of the indirection that I faced in solving this problem. At some point in this process I broke WebKit and had to installed the 3.1.1 Safari upgrade from apple, (As described by: http://soakedandsoaped.com/articles/read/how-to-fix-broken-webkit-framework-after-safari-3-1-upgrade ) which updated my WebKit binary, but did not give me header files. Luckily the header files from the above /Developer/SDKs/ worked with this new WebKit binary. However the WebKit binary located in /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/WebKit.framework did not work with my version of Safari, and still gave me errors when I tried to load it using import WebKit in the python code I was testing. In short, I managed to get everything working, and I believe the root of my problem was a missing Headers directory, but I might have also needed to install Safari to fix issues with my existing WebKit install so that I could install and compile PYOBJC with WebKit bindings.

It is likely that all of these problems are fixed on Leopard, so it’s unlikely anyone else will run into these problems. I believe Leopard comes with PYOBJC preinstalled, so no worries linking the two.

So anyway I got it all working and it was worth it, webkit2png.py is far superior to the konquerer based khtml2png2 even though it was a real pain to configure on Tiger.

I guess this is a little off topic.