I am interested in creating a dmg disk image on MacOS X from Python, and came across the following solution: How do I create a nice-looking DMG for Mac OS X using command-line tools?
However, I am running into a strange issue related to path lengths. The following script illustrates my problem:
import os
import Image
for NAME in ['works', 'doesnotwork']:
    if os.path.exists(NAME + '.dmg'):
        os.remove(NAME + '.dmg')
    if os.path.exists('/Volumes/' + NAME):
        raise Exception("Need to eject /Volumes/%s first" % NAME)
    nx = 256
    ny = 256
    image = Image.new("RGB", (nx, ny))
    for i in range(nx):
        for j in range(ny):
            image.putpixel((i, j), (i, 0, j))
    os.system('hdiutil create -volname %s -fs HFS+ -size 10m %s.dmg' % (NAME, NAME))
    os.system('hdiutil attach -readwrite -noverify -noautoopen %s.dmg' % NAME)
    os.mkdir('/Volumes/%s/.background' % NAME)
    image.save('/Volumes/%s/.background/background.png' % NAME, 'PNG')
    apple_script = """osascript<<END
    tell application "Finder"
       tell disk "%s"
           open
           set current view of container window to icon view
           set toolbar visible of container window to false
           set statusbar visible of container window to false
           set the bounds of container window to {{100, 100, 355, 355}}
           set theViewOptions to the icon view options of container window
           set the background picture of theViewOptions to file ".background:background.png"
           close
           open
       end tell
    end tell
    END""" % NAME
    os.system(apple_script)
If run, the background will get correctly set in the disk image called 'works', and not in the one called 'doesnotwork'. It seems that I am limited to 5 characters for the volume name. However, if I shorten the name of the folder use to store the background, e.g. to .bkg instead of .background, then I can use a longer volume name, which suggests this is an issue related to the length of the overall path. Does anyone know at what level there is a limit on the path length? Is there a workaround to allow arbitrarily long paths?
EDIT: I am using MacOS 10.6 - the script seems to work correctly on 10.7
 
     
    