Computer: October 2006 Archives

How do I quit Emacs again?


Something really funny just happened. After I figured out how to compile Mozart on my MacBook Pro, I tried to run it and it opened Emacs in my terminal with the Oz interpreter running. And... I was stuck: I could not remember how to quit it (and I tried ctrl-Q, ctrl-W, esc-Q (I did not try the obvious ":q" ;-) )).

I then realized I have not used Emacs for more than 6 years, so I guess this explains my memory loss. (And I'm writing this in TextMate, by the way...)

2 comments were on Haloscan

You don't quit emacs! clin_oeil.gif
Nate | Homepage | 26.10.06 - 05:51

For full disclosure, I should now say that I have carbon emacs installed.

The dark side pulls strongly clin_oeil.gif
Alan Schmitt | Homepage | 26.10.06 - 08:46

By some unfortunate turn of events, I find myself without an iPod and wanting to listen to some podcasts. But as I have something that should be able to play mp3 and aac files (namely a Palm T|T3), I decided to use it to listen to them.

Now everything works well, with one glaring exception: there is no automatic way to tell iTunes that I listened to a podcast, hence removing it from my (very small) playlist that has to fit on a small SD card. The crux of the issue is that I could not find a player that recorded the played count and could update it on iTunes.

So I decided to take another route: podcasts are just files, so they are synchronized using the Missing Sync file synchronization conduit. When I listen to them on iTunes, they get removed from the smart playlist I use (when their played count is greater than 0), so by getting the files out of iTunes to some folder on my laptop, I could get a one way synchronization.

To have a two way synchronization (files listened on the palm gets removed from the playlist), I decided to do the following simple approach: when I have listened to a podcast on the palm, I delete it from the card, and upon next Missing Sync synchronization, it gets removed from the corresponding laptop folder.

So now I have to tie all this together, by remembering which files went on the palm. The idea is fairly simple (and shamelessly steals from the archive idea of Unison).

  1. For every track in the iTunes playlist that is not present in the folder
    • if it not mentioned in the archive, it is new, so it is copied to the folder, and an empty file is created in the archive with the same name and its comment sets to the track name;
    • if it is mentioned in the archive, it was deleted (hence listened on the palm), so the track gets a played count of 1 (which removes it from the smart play list).
  2. For every file in the archive, if its comment is not the title of a track in the iTunes smart playlist, it was listened in iTunes, so the archive file and the track file are deleted (and will be removed from the Palm).

I'm using the fact that files will never be added on the Palm side, which make the previous algorithm a bit better.

Now for the implementation: - the script run on my home machine (that has the iTunes library); - the folder with the songs is synchronized to the laptop using Unison; - the folder on the laptop is synchronized with the Palm using Missing Sync.

And the script. Have fun ;-)

-- the root directory
set palmtunes to alias ((path to desktop folder as text) & "PalmTunes")

-- the directory to synchronize with the Palm
set filetunes to alias ((palmtunes as text) & "Files")
-- the directory to hold the archives (to remember what was synchronized
set archtunes to alias ((palmtunes as text) & "archive")

tell application "iTunes"
  -- the following playlist should be a smart playlist that only contain 
  -- songs with a play count of 0

  set smartlist to user playlist "AB Palm"
  set palmtracks to a reference to file tracks of smartlist
  -- We first synchronize songs that are present in iTunes
  repeat with aTrack in palmtracks
    set trackfile to location of aTrack
    set trackname to name of aTrack
    set filename to name of (info for trackfile)
    tell application "Finder"
      if not (exists file filename of filetunes) then
        -- was it synchronized?
        if (exists file filename of archtunes) then
          -- it was synchronized and has been deleted on the palm, then 
          -- remove it from iTunes
          tell application "iTunes"
            set (played count of aTrack) to 1
          end tell
          set theFile to alias ((archtunes as text) & filename)
          delete theFile
          duplicate trackfile to filetunes
          make new file at archtunes with properties {name:filename, comment:trackname}
        end if
      end if
    end tell
  end repeat
  -- We now remove songs that are present in the archive but not in the
  -- playlist anymore
  tell application "Finder"
    set archfiles to items of folder archtunes
    repeat with aFile in archfiles
      set trackname to the comment of aFile
      -- search if the track is in the playlist
      tell application "iTunes"
        set mytrack to (every track of smartlist whose name is trackname)
      end tell
      if (length of mytrack is 0) then
        -- This track was removed from iTunes, we need to remove it
        set aFileName to name of aFile
        delete aFile
        delete (alias ((filetunes as text) & aFileName))
      end if
    end repeat
  end tell
end tell

4 comments were on Haloscan

Sigh I wish I was more familiar with AppleScript. How should I modify this script to use with a Finder folder of files, instead of an iTunes playlist, but still updating the iTunes playcount?
Jim A Syler | Homepage | 05.01.07 - 18:52

I'm really no expert at AppleScript either (I believe it's a read-only language). The tricky part is figuring out which files correspond to which iTunes entry. To do so, you can look at the last part of the script, where I look at every file present in the folder, get the track name from the spotlight comments (where I first set them), and search for it in iTunes. (You can specify the whole Library as the playlist, if I remember correctly.)

Good luck.
Alan Schmitt | Homepage | 05.01.07 - 19:34

Haha! I did it! I'll post the result on my blog and trackback it to here. Thanks for your wonderful script; it wouldn't have been possible without it!
Jim A Syler | Homepage | 08.01.07 - 23:32

Cool. I could not find your post on your blog though (the last one is from mid-december).
Alan Schmitt | Homepage | 09.01.07 - 10:07

Je suis en train de tester Tangerine, une petite application tout simple mais pleine de promesses.

Son principe est simple: Tangerine analyse les chansons de votre bibliothèque iTunes et indique pour chaque chanson son tempo (beat) et l'intensité de celui-ci (beat intensity). Cela mets un certain temps (3h30 sur mon vieil iMac G5 1.6 GHz qui a environ 80 GO de musique) mais une fois que c'est fait, c'est fait. (J'attends avec impatience qu'il atteigne mon album de Ludwig Von 88 pour voir ce qu'il trouve ;-) .)

On peut ensuite utiliser cette information pour se faire des listes de chansons "qui balancent" ou "qui endorment". J'imagine que ce soft peut faire plus, mais je trouve déjà ceci très intéressant: tout ce qui enrichit les méta-données de mes documents (images, musique, photos, vidéo, ...) leur donne bien plus de valeur, car c'est un moyen supplémentaire pour faire des recherches ou les trier.

Mise à jour: Alors que je finissais de taper ceci, Tangerine a planté. Ce qui m'a permis deux choses: de voir que Tangerine sait reprendre l'analyse là où elle s'est arrêtée (ou plus précisément, ne pas analyser à nouveau les chansons ayant déjà un tempo), et que l'interface pour explorer les tempos est assez sympathique, surtout quand on a des images associées aux albums. Chaque chanson est un rectangle, le tempo est sa hauteur, la durée sa largeur, et le rectangle contient l'image de l'album.

Mise à jour 2: L'analyse a finalement pris 1h47.

Someone on the 43Folders Google Group asked how to mail some files present in a folder every day. I thought it would be a fun challenge to do with Automator so here are the results (which I also sent to the group).

  1. Launch Automator;
  2. Click on the "Finder Library" on the left pane, then drag the "Get Specified Finder Items" action to the right pane;
  3. Click on the '+' in the newly added action and choose the folder you would like to send by email (you could also choose individual files);
  4. Click on the "Mail Library" on the left pane, then drag the "New Mail Message" action to the right pane, under the previously added actions;
  5. Enter the destination mail address, the subject, and a message body (if you want so);
  6. Drag the "Send Outgoing Messages" (still in the "Mail Library") to the right under the previous actions;
  7. Hit the "Run" button at the top right to test if everything work.

In the case you need to input some password when sending an email, you will then be asked for it.

Now you only need to save this workflow as an iCal alarm. To do so, choose "Save As Plug-in" in the "File" menu, choose "iCal alarm" in the "Plug-in for" dropbox, and choose a name. This will open iCal and create a new event with this workflow as an alarm. You may change the date and recurrence of this event to suit your needs. You may also create a new event, and give it an alarm of type "Open File" and choosing your alarm in the drop down list.

There is a more Unix solution using the mail command line program and either Launchd or Cron, but this seemed like more fun ;-)

2 comments were on Haloscan

Interesting. I'll try that to get started with Automator.

I've been interested for a while in adding to the finder the ability to create symlinks (not aliases) by drag-and-drop à la KDE, using Ctrl-Shift-drop.

The solutions I've found typically add an entry in a context menu, which is not an option when you want to create hundreds of symlink an hour (you might wonder why, I'll eventually talk about that on my blog). I really need to take an item, drag it to the location of the link to create, not type anything. Today I use KDE for this but I may want to do that with a Mac soon.

Alternatively, I'm planning to create a script that converts all alias in a directory (recursively) into posix symlinks. I'll start by modifying the code below (found in 3017.html) but you might have a better idea.

on open (item_list)  
tell application "Finder"  
repeat with theItem in item_list  
set targetPath to (get POSIX path of theItem)  
display dialog "Enter link name:" default answer "" buttons {"Cancel", "Create Link"} default button 2  
copy the result as list to {linkName, button_pressed}  
set chosen to choose folder with prompt "Pick location of symlink"  
set chosenFolder to (get POSIX path of chosen)  
do shell script "ln -s \" & targetPath & " " & chosenFolder & "/" & linkName & ""  
end repeat  
end tell  
end open

PS : I thought that your blog was self-hosted. This comment form seems not on your blog but on (and has ads).
Stéphane | Homepage | 20.10.06 - 11:23

I can't help you with the symlink thing, I've never tried it. But you could try to bind a script to a quicksilver trigger, which might make it relatively painless.

About the PS: the blog is self hosted, but I did not want to roll out my own comment system, so I'm using Haloscan, which I find works fairly well.
Alan Schmitt | Homepage | 20.10.06 - 16:02

PowerBook 170, meet MacBook Pro


This has been staying forever in some Someday/Maybe list, but as I'm going through it this morning, this is a good time to post it.


I found the old PowerBook while cleaning some room at our office. It still boots, which is amazing. It has 8MB or RAM and a 250 MB SCSI hard drive. Neat, isn't-it?

4 comments were on Haloscan

I prefer the one on the right. clin_oeil.gif
Stéphane | Homepage | 16.10.06 - 17:55

Well, the battery sure lasts longer clin_oeil.gif
Alan Schmitt | Homepage | 16.10.06 - 21:41

en plus, ça faisait moins plateau repas !!!:=)
ouss | 09.11.06 - 19:57

C'est malin clin_oeil.gif

En parlant de plateaux, sers-tu tes remerciements sur un plateau ?


Alan Schmitt | Homepage | 09.11.06 - 23:20

About this Archive

This page is a archive of entries in the Computer category from October 2006.

Computer: July 2006 is the previous archive.

Computer: December 2006 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Recently Played Games