An Applescript for playing DVD’s off of your local drive

Joshua, now 2 and a half, loves to watch his Thomas the Tank Engine movies. I want to keep him away from the original media.. so the contents of the DVD is now on my drive.

Being irritated at the number of clicks I had to go through to play it, I found a script that would make things simple.

Thanks to the folks on the forums at applescript.net who also wanted to do this!.

Anyhow, here’s the script:

set prefix to “ExternalHD:”
set suffix to “:VIDEO_TS:”
set choice to “”
tell application “Finder”
set movies to the name of every item of alias prefix
set choice to (choose from list movies with prompt “Pick a movie to watch”)
set themovie to ((prefix & choice & suffix) as alias)
end tell

tell application “DVD Player”
activate
open dvd video folder themovie
set viewer full screen to true
play dvd
end tell

To use it you will need to edit the “ExternalHD:” to match wherever your movies are.

JFLAP

Mental note: If for some really bizzare reason I might need to draw lines pointing at circles, or try to figure out if
S -> aSb|aS|รŽยต actually matches L={a^ib^j| i>=j}, I will try to solve the problem by hand first. However, in event I am really lazy, and forgot how to convert an NFA to DFA or actually want to trace the stack of a PDA matching a CFG, I will download JFLAP and use it.

Now, why did I discover this thing after I wrote my final exam? So that I could learn how to do it by hand, that’s why. It would have rocked my world about 3 months ago, but I probably would have failed the exams, relaying on it to do everything for me.

Oh, and notation it uses for CFG/PDA is somewhat different from one used in Sipser (Which is a damn fine book, BTW. Unlike Lawson it actually covers CFLs.).

P.S Mark Lawson actually makes reasonably good notes available on his page about basic automata. It still doesn’t go into CFLs/PDAs.

iBook and ATI video

So I installed ATI Displays for Mac OS X version 4.5.6….

Little did I know….

My iBook (G4 late 2004, 1.2Ghz 12″) started randomly locking up. Easiest way to trigger the lockup was by starting up matlab.

After some panicing on my part I’ve decided that maybe it’s my RAM that is failing – matlab tends to gobble up all the RAM you have and then some. Of course this happened just when I urgently needed to graph something that was due in a couple of hours.

I’ve re-seated the RAM in the iBook,
downloaded and installed memtest for Mac OS X , booted into single user mode (CMD-S on bootup), and run memtest all 3 -L.

Memtest took forever (1 gig stick + quarter gig on board), but didn’t find any problems.

So while in single user mode, I’ve started looking into /var/log/system.log.

Found this little gem:

Nov 23 11:53:32 gilva kernel[0]: ** ASIC Hang Log Start **
Nov 23 11:53:32 gilva kernel[0]: 0x01005c63 4f000217 00000007 00000003
Nov 23 11:53:32 gilva kernel[0]: 0x0200a859 c0001c04 00000002 00000008
Nov 23 11:53:32 gilva kernel[0]: 0x00004443 01e1f827 00000e0e 80010140
Nov 23 11:53:32 gilva kernel[0]: 0x4000ffff 001e0000 51b3a220 72001005
Nov 23 11:53:32 gilva kernel[0]: 0x080a0f00 00000000 040100f8 80000003
Nov 23 11:53:32 gilva kernel[0]: 0x0008bbbb 00000002
Nov 23 11:53:32 gilva kernel[0]: 0:0x000101ce
Nov 23 11:53:32 gilva kernel[0]: 1:0x10014020
Nov 23 11:53:32 gilva kernel[0]: 2:0x00000002
Nov 23 11:53:32 gilva kernel[0]: 3:0x000101ce

[about 1020 lines more of similar kernel messages]

Nov 23 11:53:42 gilva kernel[0]: 1021:0xffffffff
Nov 23 11:53:42 gilva kernel[0]: 1022:0xffffffff
Nov 23 11:53:42 gilva kernel[0]: 1023:0xffffffff
Nov 23 11:53:42 gilva kernel[0]: 0x56500bb3
Nov 23 11:53:42 gilva kernel[0]: ** ASIC Hang Log End **
Nov 23 11:53:42 gilva kernel[0]: ATIRadeon::submit_buffer: Overflowed block waiting for FIFO space.   Have 5, need 6. RBBM_STATUS 0x80010140. VAP_CNTL_STATUS 0x00000002
Nov 23 11:53:53 gilva kernel[0]: ** ASIC Hang Log Start **
Nov 23 11:53:53 gilva kernel[0]: 0x01005c63 4f000217 00000007 00000003
Nov 23 11:53:53 gilva kernel[0]: 0x0200a859 c0001c04 00000002 00000008
Nov 23 11:53:53 gilva kernel[0]: 0x00004443 01e1f827 00000e0e 80010140
Nov 23 11:53:53 gilva kernel[0]: 0x4000ffff 001e0000 51b3a220 72001005
Nov 23 11:53:53 gilva kernel[0]: 0x080a0f00 00000000 040100f8 80000003
Nov 23 11:53:53 gilva kernel[0]: 0x0008bbbb 00000002
Nov 23 11:53:53 gilva kernel[0]: 0:0x000101ce
Nov 23 11:53:53 gilva kernel[0]: 1:0x10014020
Nov 23 11:53:53 gilva kernel[0]: 2:0x00000002
Nov 23 11:53:53 gilva kernel[0]: 3:0x000101ce
Nov 23 11:53:53 gilva kernel[0]: 4:0x10016020

[ ditto ]

Nov 23 11:54:03 gilva kernel[0]: 1021:0xffffffff
Nov 23 11:54:03 gilva kernel[0]: 1022:0xffffffff
Nov 23 11:54:03 gilva kernel[0]: 1023:0xffffffff
Nov 23 11:54:03 gilva kernel[0]: 0x56500bb3
Nov 23 11:54:03 gilva kernel[0]: ** ASIC Hang Log End **
Nov 23 11:54:03 gilva kernel[0]: ATIRadeon::submit_buffer: Overflowed block waiting for FIFO space.   Have 5, need 6. RBBM_STATUS 0x80010140. VAP_CNTL_STATUS 0x00000002
Nov 23 11:54:15 gilva kernel[0]: ** ASIC Hang Log Start **
Nov 23 11:54:15 gilva kernel[0]: 0x01005c63 4f000217 00000007 00000003
Nov 23 11:54:15 gilva kernel[0]: 0x0200a859 c0001c04 00000002 00000008
Nov 23 11:54:15 gilva kernel[0]: 0x00004443 01e1f823 00000e0e 80010140
Nov 23 11:54:15 gilva kernel[0]: 0x4000ffff 001e0000 51b3a220 72001005
Nov 23 11:54:15 gilva kernel[0]: 0x080a0f00 00000000 040100f8 80000003
Nov 23 11:54:15 gilva kernel[0]: 0x0008bbbb 00000002
Nov 23 11:54:15 gilva kernel[0]: 0:0x000101ce
Nov 23 11:54:15 gilva kernel[0]: 1:0x10014020
Nov 23 11:54:15 gilva kernel[0]: 2:0x00000002
Nov 23 11:54:15 gilva kernel[0]: 3:0x000101ce
Nov 23 11:54:15 gilva kernel[0]: 4:0x10016020
[...]

Based on what I understand, right now the problem is either in the hardware of the system (I’ll run the system through AHT paces once I make it home), or in the ATI Displays driver.

Joys. Somehow my bet is on ATI Displays kernel drivers being buggy. This agrees with me:

On Dec 29, 2004, at 9:37 AM, Avelino Santa Ana Jr. wrote:

Dec 27 21:52:27 localhost kernel: ATIRadeon::submit_buffer: Overflowed block waiting for FIFO space. Have 4, need 6. RBBM_STATUS 0x80116100. VAP_CNTL_STATUS 0xd4f40002


Howard Shere
http://blogs.greendragon.com/index.php/gdc
Altair 8800a to Mac OS X so far...

Hi,
Are you using vertex programs in your port? What hardware are you using? Is it an R200 based chipset (Radeon 8500-9200)? If so, I recall seeing similar issues with a couple of games I beta tested. The problem had to do with the R200 drivers and vertex programs. I'm not sure how the developers solved them.

I just glanced in the archives and Nicholas Francis noted a cause in his app (fog and vertex programs). This was in May 18, 2004 "Re: ARB vartex program crashbug"

[...]

I’ve run 4.5.1 for months with no problems, so I guess I will be reverting to that version, and will see if the problem went away.

Update 20051207: I broght iBook home that day, and run the extended tests using Apple Hardware Diagnostics disk. It passed all tests without any problems, although a gig of Kingston RAM took about 20 minutes to check.

Once I booted the system back up, it locked up about a minute after loging in.
I rebooted, and it locked up at the blue screen that shows for a few seconds while various services are loading (first graphic screen, essentially).

At that point I were still thinking that maybe something is wrong with my install of the OS.

I tried booting from a bootable CD of 10.3.4 (Some repair disk I downloaded a good long while ago, that essentially was starting up, creating RAM disk, and starting 10.3.4 to Finder, with a few diagnostic applications and Terminal.app), but system also locked up as soon as graphic mode started. By this point I knew that the probem is not with the OS. When I booted from the 10.3.5 install DVD that was originally shipped with the system, and it locked up, I knew for certain that the problem is with the video circuitry on the logic board.

I broght it to my local authorized service provider (who gets no link and remains nameless, because they are not great), their technican checked it out, confirmed that the logic board is malfunctioning, and ordered a replacement logic board. At this time system is less then a year old (bought late december 2004).

Looking for Disk Image Automator Actions!

Does anyone know of an Automator action, or Big Cat script, that when you right click on a mounted Disk Image, will unmount it and *delete* the original image.

Why? Well.. My download folder is huge.. and I need a faster way to look into a mounted disk image, test out whatever is in there and then delete it. If I like the application, or whatever it is, I will copy it to a more permanent location, and still need to delete the original!!!

If no such thing exists I’ll cobble one together, which should not be too hard seeing as I can start with Laine Lee’s work: Show Disk Image File of Selected Volume

DYLD_LIBRARY_PATH

Anyhone has any clue why vast majority of the dynamic linkers out there (Solaris, Linux, BSD etc) all use LD_LIBRARY_PATH variable to specify where to load dynamic libraries from, yet Darwin/MacOS X uses DYLD_LIBRARY_PATH?

*grumble*

Compiling Alladin GhostScript 8.51 from source. It’s not hard, just quirky. Oh, and jpgsrc-6 and zlib-1.2.2 both need a config.sub from a recent package for configure to recognize Darwin/MacOS X.

Shellscripts: Using ANSI colors or finding duplicate files in style

… or “ASCII stupid questions, get a stupid ANSI”….

I’ve been writing Evil Shell Scripts of Doom[tm] lately, got curious in highlighting parts of the output in different color.
As both Terminal.app and xterms in Apple shipped X11 support ANSI colors, it made sense to me.

There are excellent How to Change a Title of an Xterm and Bash Prompts HOWTOs out there, to which I’ll refere my gentle reader, and thus I will just paste some example code.

Bits that directly relate to ANSI color output are all the echo -e lines, with basic logic being that echo -ne “e[1;35m” turns ON purple color, and echo -ne “e[0;m” turns it off. Of course other numeric values will generate different colors, and colors will look different on different terminals. Please refere to HOWTOs above.

Please make sure that you BOTH understand what this does, and undertand that YOU are responsible for running this. If it breaks, you get to keep both pieces, and not cry in my shoulder. The following is copyright 2005 Stany, and is licensed under… *shrug* BSD 2 clause license, in hope that this will be useful to others

(This is just some internal code that in reality just externalizes a function out of a much larger script, however might be of use to others without revealing what exactly I were working on. Note that it will leave an md5sum.out file behind, and will generate a script called “killfile” to remove duplicate if they were detected. This script doesn’t do many sanity checks, as they were job of a larger script, and will barf if subdirectories are present and matched. )

#!/bin/bash
# Checks for duplicates.  Takes one argument (optional) of the file ending,
# eg: checkdupe.sh pdf
# $Id: checkdupe.sh,v 1.2 2005/09/06 06:56:11 stany Exp stany $
MD5SUM=/opt/gnu/bin/md5sum
BASENAME=`basename $0`

checkdupe()
{
for ii in *$1 ; do
        FILESUM=`$MD5SUM $ii | awk '{print $1}'`
        NUMFILES=`grep $FILESUM md5sum.out | wc -l`
        if [ $NUMFILES -gt 0 ]; then
                OTHERFILE=`grep $FILESUM md5sum.out | awk '{print $2}'`
                 echo -e "e[1;31m`date` $BASENAME: e[1;36m$ii e[1;32mis a duplicate of e[1;35m$OTHERFILE e[0;m"
                echo "rm $ii" >> killfile
        else
                $MD5SUM $ii >> md5sum.out
        fi
done
}

if [ -e killfile ] ; then
        rm killfile
fi

if [ -e md5sum.out ] ; then
        rm md5sum.out
fi
        touch md5sum.out

checkdupe $1

if [ -e killfile ] ; then
        echo -e "e[1;31m`date` $BASENAME: Duplicates found.  Run killfilee[0;m"
        echo -ne "e[1;35m"
        cat killfile
        echo -ne "e[0;m"

fi


Sample run:

stany@gilva:~[02:58 AM]$ mkdir test
stany@gilva:~[03:04 AM]$ cd test/
stany@gilva:~/test[03:04 AM]$ echo a >foo 
stany@gilva:~/test[03:04 AM]$ echo a >bar 
stany@gilva:~/test[03:04 AM]$ echo b > baz
stany@gilva:~/test[03:04 AM]$ ../checkdupe.sh 
Tue Sep  6 03:04:45 EDT 2005 checkdupe.sh: foo is a duplicate of bar 
Tue Sep  6 03:04:45 EDT 2005 checkdupe.sh: Duplicates found.  Run killfile
rm foo
stany@gilva:~/nature/test[03:04 AM]$ ls
bar             baz             foo             killfile        md5sum.out
stany@gilva:~/nature/test[03:04 AM]$ 

Oh, and checkdupe() can be trivially fixed so that it would take any shell expandable expression as an argument to the script, and work with that. I don’t even consider it an excercise ๐Ÿ˜›

MacOSX: Trimming fat from Mach-O fat files

MacOS X uses fat files.

A fat bundle contains data for different architectures. Here are some examples:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:03 AM]# file *
Terminal: Mach-O fat file with 2 architectures
Terminal (for architecture i386):       Mach-O executable i386
Terminal (for architecture ppc):        Mach-O executable ppc
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:03 AM]# 

or even:

stany@gilva:/System/Library/Frameworks/Accelerate.framework/Versions/A[02:07 AM]$ file Accelerate 
Accelerate: Mach-O fat file with 3 architectures
Accelerate (for architecture i386):     Mach-O dynamically linked shared library i386
Accelerate (for architecture ppc):      Mach-O dynamically linked shared library ppc
Accelerate (for architecture ppc64):    Mach-O 64-bit dynamically linked shared library ppc64
stany@gilva:/System/Library/Frameworks/Accelerate.framework/Versions/A[02:07 AM]$ 

In order to operate on fat bundles Apple provides a utility called lipo.

If you are in a situation where you are limited by processor architecture – for example, if you never expect to use internal hard drive of your iBook in firewire target mode to boot up an i386 system – it is possible to remove the extra “fat” from fat binaries, to save some disk space.

Here is an example:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:09 AM]# mv Terminal Terminal.bak 
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# ls
Terminal.bak
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]#lipo Terminal.bak -remove i386 -output Terminal
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# ls -la 
total 2296
drwxrwxr-x   4 root  admin     136 Sep  6 02:10 .
drwxrwxr-x   7 root  admin     238 Aug 31 00:07 ..
-rwxr-xr-x   1 root  admin  386472 Sep  6 02:10 Terminal
-rwxrwxr-x   1 root  admin  783784 May 14 22:22 Terminal.bak
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# file *
Terminal:     Mach-O fat file with 1 architecture
Terminal (for architecture ppc):        Mach-O executable ppc
Terminal.bak: Mach-O fat file with 2 architectures
Terminal.bak (for architecture i386):   Mach-O executable i386
Terminal.bak (for architecture ppc):    Mach-O executable ppc
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]#

A quick test confirms that Terminal.app continues to run as before, however to make sure that everything is kosher I would probably want to correct permissions on the new binary to match what it was on the original.

Disk space saving will not be big, as an average .app consists of many other objects besides the executable itself, so this is probably not a very big issue. If one tries to remove a non-existing architecture from a binary, lipo will complain:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:18 AM]# 
lipo Terminal.bak -remove ppc64 -output Terminal
lipo: -remove ppc64 specified but fat file: Terminal.bak does not contain that architecture
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:19 AM]#

Another interesting option to lipo is -detailed_info:

stany@gilva:~[02:22 AM]$ lipo -detailed_info /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate 
Fat header in: /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
fat_magic 0xcafebabe
nfat_arch 3
architecture i386
    cputype CPU_TYPE_I386
    cpusubtype CPU_SUBTYPE_I386_ALL
    offset 4096
    size 8488
    align 2^12 (4096)
architecture ppc
    cputype CPU_TYPE_POWERPC
    cpusubtype CPU_SUBTYPE_POWERPC_ALL
    offset 16384
    size 8564
    align 2^12 (4096)
architecture ppc64
    cputype CPU_TYPE_POWERPC64
    cpusubtype CPU_SUBTYPE_POWERPC_ALL
    offset 28672
    size 8488
    align 2^12 (4096)
stany@gilva:~[02:22 AM]$ 

writing a script that processes the output of:

 find . -type f  -perm -55 -exec file {} ; | grep i386 | sed 's/.for arch.*$//g'

while stripping out the arch, AND not screwing up the system is left as an excercise for the reader. ๐Ÿ˜›

Rendering a manpage

This is more of a general unix hint, that is not really MacOS X specific.

If you have a manpage that you want to look at, that is not in $MANPATH, (Something that got installed by hand into a custom directory, for example something that was built and installed using
./configure –prefix=/opt/packagename && make install ), yet you know where it is (for example because you did run /usr/libexec/locate.updatedb as root at least once since and now can use locate), you can use nroff to render the man page into text:

stany@gilva:~[12:06 AM]$ ls -la /opt/gnu/man/man6/figlet.6 
-r--r--r--   1 root  501  21054 Sep  3 17:41 /opt/gnu/man/man6/figlet.6
stany@gilva:~[12:06 AM]$ nroff -man /opt/gnu/man/man6/figlet.6 | head -20
FIGLET(6)                                                            FIGLET(6)



NAME
       FIGlet - display large characters made up of ordinary screen characters


SYNOPSIS
       figlet [ -cklnoprstvxDELNRSWX ] [ -d fontdirectory ]
              [ -f fontfile ] [ -m layoutmode ]
              [ -w outputwidth ] [ -C controlfile ]
              [ -I infocode ] [ message ]


DESCRIPTION
       FIGlet prints its input using  large  characters  (called  ``FIGcharac-
       ters'')made  up  of  ordinary  screen  characters (called ``sub-charac-
       ters'').  FIGlet output is generally reminiscent of the sort of  ``sig-
       natures''  many people like to put at the end of e-mail and UseNet mes-
stany@gilva:~[12:06 AM]$ 

Turning a man page into a PDF

In the end of a series of comments on Mike Harris’s article about Remind:

[minor edits by davidr]


#!/bin/sh

manpage to PDF generator

2004-08-02, Christopher Hansen

http://emilyandchristopher.com/

Usage: pdfman command

Creates command.pdf in current directory.

mandoc=/usr/bin/env man -w $1
grcmd=/usr/bin/env grog $mandoc
/usr/bin/env $grcmd | ps2pdf - > $1.pdf

To use it, select and copy the previous 11 lines. Then type the following into a Terminal window:

pbpaste > pdfman
chmod +x pdfman
cp pdfman ~/bin/

Now, if you type “pdfman remind” in a Terminal window, you’ll end up with a file called remind.pdf.

43 Folders Mike Harris looks at Remind

Thanks Christopher!