[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] VCard - Seek and destroy script



I am forever trying to decide whether to use an MPW script or a perl script which I would run under MPW anyway. It may be my pre-perl experience but I usually find the MPW script easier to set up.

Below is a short MPW script which I have been using to "seek and convert" *.pdf files to Acrobat Exchange files by changing the creator code. It could easily be altered to find *.vcf files and delete them (check ### lines below). It also has a feature in that it does not actually alter the files. Rather it puts out a string of MPW commands to STDOUT which can be selected and executed. You get to look at the list to see if that's in fact what you have in mind.

The longer lines and 8 bit characters of MPW may get messed up in the mail but the idea will be clear. If you'd like a better copy please ask.

Typical call:
Luna:Doug:CreatorSet Luna:
produces this output:
setfile -c CARO 'Luna:Documents:Data Sheets:Osc_32k_saronix_124.p1.pdf'
setfile -c CARO 'Luna:Documents:Data Sheets:VB409 appnote 6939.pdf'
setfile -c CARO 'Luna:Documents:Data Sheets:VB409 regulator 6941.pdf'

Long live MacPerl under MPW. Please keep it working that way under MacOS exx.

# Script to scan recursively from a starting directory for *.pdf files
# Puts out setfile commands to change creator to Adobe Acrobat Exchange.
# Doug McNutt <dmcnutt@macnauchtan.com>
# Saturday, August 12, 2000 13:05:30
set exit 0
if {#} ¾ 1
    set incoming `directory`
# If there are less than 2 arguments we are starting up so get the starting directory which will be the place where we reside
# Develop the complete path to this script for reentry. Needed because we only get the filename if MPW calls this from its working directory.
#   (evaluate "{0}" =~ /(([¬:]+:)*)®1‰/) > dev:null  # MPW Cmd Ref p 183. - Mine, below, seems simpler. I wonder...
    (evaluate "{0}" =~ /(‰:)®1‰/) > dev:null
    if "{®1}"
        set scriptDir "{®1}"
        set myPath "{0}"
    else
        set scriptDir `directory`
        set myPath "{scriptDir}{0}"
    end
    export myPath
    if {#} == 0
#        If there are no arguments then set up a loop thru all known volumes
#        This will restart at the top of this script, but there will be two arguments so we will go to the else clause
        for vol in `volumes`
            echo {vol}  … dev:null
            if {Status} != 0
                echo {vol} error at 111   „ dev:null
            end
            "{myPath}" "{{vol}}" "dummy"   „ dev:null 
        end
    else
#       If there is one argument  it is the starting directory. Recall recursively.
        "{myPath}" "{1}" "dummy"   „ dev:null 
    end
    exit 0
    
else
#    if there are two arguments we are getting called recursively.
#    Set the working directory to the argument - it might be a volume
#    then check to see if it happened - we might not be allowed to use it.
    directory `quote "{{1}}"`
    if {Status} != 0
        echo "### Unable to use folder - " "{{1}}"
        exit {serial}
    end
#    Remember where we are for the output file and for later recursion
    set curDir `directory`
#    Now look at the files in this directory - ignore the folders
#    Be very careful with quoting - a filename with > in it can create an unexpected redirection file
    for ffs in `files -f -o -s ‰.pdf`  ### change to ‰.vcf
        if `files -c CARO "{fff}"` == 0  ### remove
            echo -n "setfile -c CARO "  ### Change to echo -n "delete "
            quote "{ffs}"
        end
    end
#    now look for any folders present and do them with a recursive call
#    We need to change the directory to current because we're passing a partial path to the sub script.
#    Remember that the directory is changed in each call and that the setting is not retained in a stack.
#    It's too bad exported variables don't seem to work the same way.
    for folder in `files -d`
        directory "{{curdir}}"
        "{myPath}" "{{folder}}" "dummy"
    end
    exit
end
-- 

-> From the U S of A, the only socialist country that refuses to admit it. <-

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org