From: Greg Ercolano <erco@(email surpressed)>
Subject: [Q+A] How do I make custom versions of submit scripts for OSX?
   Date: Thu, 24 Aug 2006 00:18:43 -0400
Msg# 1378
View Complete Thread (2 articles) | All Threads
Last Next
> i'd like to make a copy of the submit-maya.pl script so i can
> make customizations for specific purposes. but i want to leave
> the original in place for other users to use.
>
> i made a copy of submit-maya.pl called submit-maya-IPR.pl,
> and I can invoke it from the command line just fine as:
>
> perl //ourserver/rushscripts/submit-maya-IPR.pl
>
> ..but if i try to make a copy of the Applications/submit-maya.app
> so that i can click on it from the Finder, my copy doesn't work.
> i tried both using the Finder and 'cp -r' to make the copy, but
> neither technique seems to work. what is the .app stuff anyway?

    Yes, the .app stuff.

    This is an Apple thing. For whatever reason, the designers of the OSX
    Desktop and Finder didn't implement things so that you could just run
    a script by double-clicking on it. Even if the script has execute bits
    enabled with chmod 755, the Finder will still open it in a text editor..!

    So for the Mac, the submit scripts are packaged with an 'Application Bundle',
    (the ".app" directory), which is a directory structure defined by Apple
    to replace the older 'resource fork' stuff.

    So if you create a new script, you have to create a new 'MacOS Application Bundle'
    for it too, if you want Mac users to be able to open the script from the Finder.

    Unfortunately the Mac's Finder isn't able to rename .app bundles,
    because there are files within the bundle that refer to its own name,
    and if the .app's name doesn't match the contents, the Finder thinks it's
    corrupt and won't run it.

    So you can't /just/ make a copy of a .app dir and rename it, you also have
    to fix the stuff within the bundle.

    Fortunately the .app bundles can be modified easily from the command line.
    The way to make a new copy is to do this (don't type the comments!):

cd /yourserver/jobs/rushscripts

### COPY THE SCRIPT
cp submit-maya.pl submit-maya-IPR.pl

### COPY THE .app BUNDLE, FIXUP NAMES
cp -rp Applications/submit-maya.app Applications/submit-maya-IPR.app
cd Applications/submit-maya-IPR.app
(echo g/submit-maya/s//submit-maya-IPR/g; echo wq) | ex Contents/Info.plist
mv Contents/MacOS/submit-maya Contents/MacOS/submit-maya-IPR

    By fixing the files this way, you've now made a new "Application Bundle"
    that you should be able to click on from the Finder, and it will run your
    perl script that is in the directory above the Applications dir.

    You can then edit the submit-maya-IPR.pl script to do new behavior.

    I advise you debug/test from the command line, eg:

perl /yourserver/rushscripts/submit-maya-IPR.pl

    If you try to debug by clicking on the Desktop or .app bundle, you won't be
    able to see warnings/errors from perl, because there's no terminal for the errors
    when you invoke it that way. Same goes for testing under Windows or Linux.
    Invoke it from a DOS or shell window so you can see warnings/errors during testing.

    [EDIT: Note: When you make changes to the .app's contents, you may need to
     restart the OSX "Finder" to clear its cache of old .app settings which may
     be cached from previous executions of the app before the changes were made]

Last Next