Posts Tagged ‘mac’

The Smallest Carbon Emacs Installer Ever.

Wednesday, January 9th, 2008

As noted on several other blogs posts the /usr/bin/emacs in MacOS X Leopard is built with carbon support, it simply lacks the .app wrapper. You can easily download the .app wrapper and create a symlink and away you go. So here is a shell script that does that.emacs-installer.shUsage:

  1. Download emacs-installer.sh
  2. chmod a+x emacs-installer.sh
  3. sudo ./emacs-installer.sh /Applications

Technorati Tags: ,

iRate.py v2007-06-29

Friday, June 29th, 2007

The Problem:iTunes keeps song ratings, play and skip counts in a proprietary database format.The Solution:iTunes exposes song ratins, play and skip counts via AppleScript, and I have a python->AppleScript bridge.My solution of course is not a particularly original one, Doug’s AppleScripts for iTunes includes a Tags to File Comments script. Which uses AppleScript to take ratings, play counts, skip counts, and more out of iTunes and shove it into the Spotlight comment field in the extended attributes. This was a fine, perfectly well functioning script. However the performance characteristics of both AppleScript and extended attributes makes it very very slow. On my Core 2 Duo MacBook Pro it took roughly 8 hours (I don’t actually know, I fell asleep while waiting) to export the data for ~4,430 tracks, with iTunes using 100% CPU. I don’t know how long it takes to import the data because I figured I could write something else in less than 8 hours.So after about 4 hours of coding and debugging I present to you iRate.pyIt uses AppleScript to export the the ratings, played count, played date, skipped count, skipped date to an SQLite database. It will also import the same data from the SQLite database.  It also manages to be significantly faster than Doug’s script.  The export of my library takes about 44 seconds, and another 22 seconds to import.To run it requires:

  • MacOS X 10.4 (tested on 10.4.10)
  • iTunes 7.2+ (tested on 7.2 and 7.3)
  • Python 2.5 (Universal binary available here)
  • appscript 0.17.2 (Fancy installer available here)

So there we have a simple solution to a simple problem. Here is hoping someone else finds it as useful as I did.-David

Technorati Tags: ,

Twitter + Quicksilver + Growl = Tweet+Growl

Wednesday, March 21st, 2007

A while ago after much discussion of Twitter by Leo Laporte and Merlin Mann on MacBreak Weekly I decided to sign up. I like it, I can’t explain why, I just do. It satisfies my urge to talk to noone in particular.Shortly after discovering Twitter I immediately went looking for the best way to post to Twitter. Where I found the Tweet = Twitter + Quicksilver which is a great little script, but it never told me when it was successful. (and during twitters recent downtime I Tweet’d several times.)So in the spirit of open source I decided to improve it by adding Growl support. So without further ado I present to you Tweet+Growl

tell application "GrowlHelperApp"	set the allNotificationsList to {"Success Notification", "Failure Notification"}	set the enabledNotificationsList to {"Success Notification", "Failure Notification"}	register as application ¬		"Tweet" all notifications allNotificationsList ¬		default notifications enabledNotificationsListend tellusing terms from application "Quicksilver"	on process text tweet		tell application "Keychain Scripting"			set twitter_key to first Internet key of current keychain whose server is "twitter.com"			set twitter_login to quoted form of (account of twitter_key & ":" & password of twitter_key)		end tell		set twitter_status to quoted form of ("status=" & tweet)		set results to do shell script "curl --user " & twitter_login & "-D - --data-binary " & twitter_status & " http://twitter.com/statuses/update.json"		set code to word 3 of results		if code = "200" then			tell application "GrowlHelperApp"				notify with name ¬					"Success Notification" title ¬					"Tweet Success" description ¬					"Successfully twittered \"" & tweet & ¬					"\"" application name "Tweet"			end tell		else			tell application "GrowlHelperApp"				notify with name ¬					"Failure Notification" title ¬					"Tweet Failure:" & code description ¬					"Failed to twitter \"" & tweet & ¬					"\"" application name "Tweet"			end tell		end if		return nothing	end process textend using terms from

Technorati Tags: ,

Why I switched.

Monday, March 19th, 2007

Let me start of with saying I love Linux, I love the community and I love a good bit of the software that comes on a Linux system. I am especially fond of both the Desktop and Server editions of Ubuntu. However I don’t use Linux on the Desktop anymore, and I’d like to share with my faithful readers some of the reasons why in no particular order.

  • 3 Device Filesystems in as many years. -This is a big one. I remember when /dev was just a bunch of files, and every linux system had pretty much the exact same set of files even if most of them weren’t connected to anything.Then someone decided that right thing to do was have a new filesystem called devfs, that would be mounted and only populated with the devices when the devices were connected. Now this was kind of cool sure, but not really important, however they decided it’d be really sweet to reorganize the hierarchy based on what kind of device was actually plugged in. So your cdroms would be distinguished your hard drives because they were in /dev/cdrom, etc.Then someone decided that devfs was the wrong way to do it and wasn’t worth maintaining anymore, while someone else decided that the proper way to do this would be to have a small kernel bit that talked to a user space daemon that would actually manage the device hierarchy. (Ahh the gradual microkernelization of linux with none of the benefits.) More importantly the new system (udev) would go back to all the old names, but have this really flexible (and really undocumented) configuration language that would let you use whatever naming system you wanted. Which was awesome of course, because it means udev can be backwards, forwards, and leftwards compatible, however the first time someone’s cdrom is actually /dev/poop/turd0 it gets to be a little old.
  • Windows as a useability goal -For a long time people talked about how linux wasn’t going to make it on the desktop until it felt just like using Windows. So what did all the brilliant Open Source hackers and computer scientists do?Well after much scrambling around like chickens with their heads cut off they started making things that looked and felt like Windows. Not because they stole windows look and feel, but because they made things that looked like they should be simple, and made them hard. What’s worse they remade them time and time again to make them harder and less useful. (Gnome file dialog anyone?)Windows shouldn’t be a useability benchmark and I think most of the people who are going to understand that understand it by now. Which basically leaves these smart people with two options, design things for themselves (not a horrible idea but really really hard) or crib things from Mac OSX.Not that Mac OSX is always a bastion of useable software (Finder, Mail.app come to mind) but it has a couple of things going for it, mostly that it starts out very simple and scales up to let you do complicated things (mmm… Quicksilver.) While Linux tends to start of with all these options, and not scale down very well.
  • I don’t think commercial software is a crime -Yes I’d much rather be writing and using Open Source software, but I’ve seen a lot of really cool commercial software since I’ve been using OSX (Yojimbo, Delicious Library, Pzizz, NetNewsWire, Cha-Ching.) So if there is an application that lets me use it the way I want to, and do so without a headache, I’ll pay $20, $30, or even $40 for it.So I still love open source software, but it’s hard to get paid to write Open Source software (I’m an extremely lucky individual) and if I were a more talented individual I’d probably be working for myself selling cool little applications for $30 a pop.I also understand that the really evil commercial software isn’t the thing written buy the single developer and sold for $25.99 it’s the huge multihundred dollar software that is encumbered with all sorts of horrible patents.
  • It doesn’t have Quicksilver -I spend a large portion of my life typing things into Quicksilver. I use it to capture things for Actiontastic, I use it to switch applications, I use it to launch applications, I use it to search google, to open bookmarks, to open URLs, and many other things.So not having Quicksilver on Linux is a big problem for me, a really big problem, so big that if I find myself switching back to Linux (like if someone wants to pay me to write software for it.) Then writing something as beautiful, useful, and flexible as Quicksilver will be the first thing I do.Sure there are things like it, but there is nothing quite like it. I got buy for a longtime with waffle.jl for Sawfish, and then things like LaunchBox started popping up but not quite being good enough and trying to be too pretty without being fast enough, and so I just never felt like there was a real option. The closest I came to finding something as useful and flexible as Quicksilver was Arnic, a little piece of Python, Twisted, Axiom code written by z3p (of twisted.conch infamy) I hacked on this for a bit, submitted a couple of patches, but even then ultimately came back to the QS on the X.

P.S. The GPL is a complete steaming pile of overly restrictive crap.

Technorati Tags: , ,

ctypes number of cpus

Tuesday, November 7th, 2006
#!/usr/bin/env pythonfrom ctypes import *import ctypes.utillibc = cdll.LoadLibrary(ctypes.util.find_library('libc'))def getCPUnums():    counts = {'logicalcpu': c_int(0),              'ncpu': c_int(0),              'physicalcpu': c_int(0)}    for k, v in counts.iteritems():        size = c_int(sizeof(v))        libc.sysctlbyname('hw.%s' % (k,),                          c_voidp(addressof(v)),                          addressof(size),                          None, 0)    return (int(counts['ncpu'].value),            int(counts['physicalcpu'].value),            int(counts['logicalcpu'].value))if __name__ == “__main__”:    print “”"CPU Counts:N:\t\t%dPhysical:\t%dLogical:\t%d”"” % getCPUnums()

Of course my Intel Core 2 Duo gives me the following.

sabrina dreid:~> python cpun.pyCPU Counts:N:              2Physical:       2Logical:        2

You could have just as easily done sysctl hw.ncpu hw.physicalcpu hw.logicalcpu with commands.getoutput. But ctypes is cooler and almost certainly several times faster.

Technorati Tags: , , ,