fredag 23 april 2010

Send text to Mac ClipBoard from python (like pbcopy)

def sendToClipBoard(string):
    from AppKit import NSPasteboard,NSObject,NSStringPboardType
    pasteboard = NSPasteboard.generalPasteboard()
    emptyOwner = NSObject.alloc().init()
    pasteboard.declareTypes_owner_([NSStringPboardType], emptyOwner)
    pasteboard.setString_forType_(string, NSStringPboardType)

if __name__ == "__main__":
    import sys

Idea from this marvellous post about writing a SIMBL plugin in Python.

About the building the TabDump plugin:
When I built the SIMBL plugin, I had to compile it with
/usr/bin/python py2app
and I had to set MaxBundleVersion='6531' in

Anothere way is to build it with
/usr/bin/python py2app -s --site-packages
It doesn't copy in 16 MB python stuff into the bundle.

For some reason /opt/local/bin/python doesn't work, because
then py2app makes only a i368 binary, not a x86_64 binary.  Weird.

tisdag 13 april 2010

Installation log for Oja

* In Sharing: enabled Remote Login, Remote Management, File Sharing
* Installed 3Connect
* Configured WiFi network Oja
* Enabled Internet sharing of 3 HUAWEI modem to Airport
* Installed DynDNS updater
* made the system connect the modem at boot, not at login
crontab -e
@reboot /usr/sbin/networksetup -connectpppoeservice HUAWEIMobile-Modem

* Set the system to mount disks at boot, not only at login, and keep them mounted.

sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisksWithoutUserLogin -bool true

* Disabled the SIM PIN with the 3Connect tool. (If it's on it will prompt for the SIM after a power failure which prevents automatic reconnection.)

* in System Prefs, Energy Saver set Computer Sleep to never, and check "start up automatically after power failure", and at "schedule…" set "wake up every day" at 12:00

* added this entry to the root crontab to make computer reboot if the word reboot is written into the midnight_command file

# twenty minutes past midnight
20 0 * * * grep -q reboot /Users/larsr/midnight_command && /sbin/reboot -q
# one minute to half past, every hour
29 * * * * /Users/larsr/checknet.command

* Problem: pppd for internet sharing and pppd for the 3G modem are competing and killing each other! Probably the networksetup command is no good.

* changed back so that the user logs in automatically, The start of modem connection is now handled by the login procedure.

* Set the system to share internet connection from 3G modem to airport.

* added .profile and .bashrc files to set EDITOR=nano (for easier crontab editing)

* installed Xcode from the OS X dvd, and updated the software
* installed MacPorts
* installed gphoto2 from macports
* installed a newer version of libgphoto2 2.4.9 and gphoto2 2.4.9 because it supports D5000. I changed the version number and checksums in the portfile and added a patch that I got from libgphoto2's svn repository that added a check if scsi/sg was supported (which it isn't on OS X)

* to run gphoto2, the must not be running, but it is started automatically when the camera is plugged in, so I do "killall PTPCamera" before running gphoto2. However, that makes Sofortbild not run anymore.

* necessary power outlets: 1 for UPS, 1 for Computer, 1 for Disk, 1 for Backup Disk, 1 for Camera, 1 for heater, 1 for backup laptop. Don't put heater on the UPS.

* installed kermit. check receiving strength with kermit:
kermit -l /dev/tty.HUAWEIMobile-Pcui -C "set carrier-watch off,connect" | awk '/SSI/ {print $0}'
or issue the command "AT+CSQ"

* installed Sofortbild
* the logitech quickcam vision pro need a "UVC compatible" video program to record HD. With QuickTime it's only 640x400. No - actually QuickTime can record from the camera at HD quality, but the quality sucks and the framerate is really bad. Bummer.

* Ran Apple's "Image Capture" program, which can fetch pictures from the camera's card. And set the camera to Shared, so others on the lan can now fetch from the card too.

* installed the Nikon programs that came with the camera, but they were useless so I removed them

* installed MacPorts packages tuntaposx and aiccu, and configured the IPv6 tunnel by putting the config file in /opt/local/etc/aiccu.conf, and starting the services with the launchd commands
sudo launchctl load -w /Library/LaunchDaemons/org.macports.tuntaposx.plist
sudo launchctl load -w /Library/LaunchDaemons/org.macports.aiccu.plist
It remains to see what happens when the network connection is restarted - will launchd restore it?

* installed appscript into the default python installation with "sudo easy_install appscript"

* added a kill gphoto2 before the run of gphoto2 because it sometimes hangs.

* installed gpg,  imported a public key to encrypt photos with. gave it ultimate trust,  add encryption to the click-script.

måndag 5 april 2010

Syntax highlighting code on Blogger

I am going to try out this example:
To add code, paste it into HTML and enclose it as follows:
<pre class="[LANGUAGE]" name="code">
LANGUAGE can be cpp c c++  csharp  css  delphi pascal  java  javascript  php  python  rb ruby rails ror  sql  vb  xml html xhtml xslt

Here's an example:

def hello(x):
    for i in x:
        if x < 10:
            print i
    return len(x)

Writing to pastebin via python API

The parameters are listed here:

This example's pastes only live 10 minutes. Only the paste_code parameter is required.

print "Hello World!\\n"
# send text to pastebin, use syntax highlighting
from urllib import urlopen, urlencode
args={"paste_code": text, 
print urlopen(url,urlencode(args)).read()