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

Re: [MacPerl] MacPerl and Filemaker Pro



At 2:45 PM -0600 5/18/98, Chris Johnston wrote:
>A similar posting was made on Mar 22, 1998.  However, I thought I might
>re-post to see if any new information is available.
>
>Several of us out here are in need of a few examples of MacPerl - to -
>Filemaker Pro via Apple Events.
>
>I need to retrieve mulitple fields and rows from a filemaker database
>and chew on the data then print it out--via stdout or in html to then be
>passed to a WWW server.
>
>Any examples or assistance is, in advance, greatly appreciated.
>


Here's an excerpt from a script I use regularly.   I've rearranged a few things
to make it a bit easier to follow.  

The main things to note are the AppleScript ($get_syumbols_script), and the 
coversion of the AppleScript list into a Perl array.  This example fetches
only one field.

Check out the documentation and examples in the FileMaker and Apple Events
folder installed with FileMaker Pro.

Hope this helps!

Jim


use FindBin qw($Bin);

$security_path = "$Bin:db";  
    # FMPro database is in script folder and is named 'db'

$filemaker_path = 
    'Macintosh HD:Applications:FileMaker Pro 4.0 Folder:FileMaker Pro';



$get_symbols_script = <<"END_OF_APPLESCRIPT";

set DB to alias "$db_path"
set all to {}
tell application "$filemaker_path"
    activate 
        -- because FMPro 4.0 seems to want to 
        -- be in front before doing anything....
    open DB
    show (every record of database 1 whose cell "inactive" ­ 1)
    sort by {field "symbol"}
    copy field "yahoo_symbol" to all
    close window 1
end tell
return all

END_OF_APPLESCRIPT


$list = MacPerl::DoAppleScript($get_symbols_script);  
    
print "$list\n" if $DEBUG;


# Convert AppleScript list chars { } to Perl array reference chars [ ], and
# eval to get a Perl array.
# Also handle 0 or 1 elements.

if ( $list =~ tr/{}[]/[]{}/ ) {
    $result = eval($list);
}
elsif ( $list ne '' ) { # returned single element, not list...
    $result = [ eval($list) ];
}
else { # empty result
    $result = [];
}

foreach my $element (@$result) { $element =~ tr/[]{}/{}[]/; }
    # convert {} back to [] and vice versa

# Elements of @$result array are the fetched field values

--
Jim Miner          jfm@winternet.com

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch