Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

SHEXEC ( CMD ; STDIN; PARM )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.0  (2 votes)
  Discuss this Custom Function

Erich Schmidt, none
none

The function executes a SHELL script in OS X and returns the standard output

Sample Input:
SHEXEC ("bc";"obase=$1¶$2";List(2;512+5+2^5))

SHEXEC("ls $HOME/$1";"";"bin")

SHEXEC("bc";"a=$1¶b=$2¶d=2*a^2+1¶d¶scale=5¶sqrt(d)¶a+2*b^2-261¶if(b) a/b";List(70;13))
Sample Output:
1000100101

List of all directory entries from $HOME/bin

9801
99.00000
147
5.38461


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

The function executes a shell script using the MBS plugin function "AppleScript.Run" and returns the standard output. Note, that the function is useable only for Mac users (OS X).


Parameters:

CMD - The script text as a string. For testing more sophisticated scripts it's recommendable to put the text into a text field of any database table. Before executing the script it can read (for instance) by an SQL-Statement into a script variable.

STDIN - The input data read by the script. If the script needs no data, specify an empty string.

PARM - The script parameters as a FileMaker list. Line n contains the n-th parameter. In shell scripts are the paraeters separated by a sequence of one ore more spaces. Therefore you must every parameter containing spaces enclose in single quotes. The first parameter must not begin with a - (minus).


Some further examples:

Example 1:

The following script removes multiple list entries and returns the remaining entries in original order. Assumed the variable $INPUT contains the following list:

one
two
three
one
four
six
three
seven
one
two
eight
nine
six
seven
five
sixty-four

The function call

SHEXEC ( "awk '{if( !($0 in line) ) line[$0]=NR}¶
END{for(i in line) print line[i],i}' | sort -n | sed 's/^[0-9]* //'";$INPUT; "")

produces the list

one
two
three
four
six
seven
eight
nine
five
sixty-four

If there is no need to keep the output in original sorted order you can use this:

SHEXEC("awk '{line[$0]}¶END{for(i in line) print i}'";$INPUT;"")

Exampel 2:

Consider the script

awk '{x[NR] = $0; m = length($0) > m ? length($0) : m;}
END{for(z = 1;z<NR;z++)
for( partner=z+1;partner <=NR; partner++) printf("%-*s - %s\n",m+offset(x[z]), x[z], x[partner])}
function offset(word){
n=gsub("[äöüßÄÖÜ]","",word);
return(n/2)
}'

Assumed the input contains the following lines:

Berlin
New York
Paris
Vienna

The output will be a list with all possible couples:
Berlin - New York
Berlin - Paris
Berlin - Vienna
New York - Paris
New York - Vienna
Paris - Vienna

Example 3:

If $INPUT contains a list like this (for instance given by an SQL-Statement):

M0002 2015-10-06 2015 22.3
M0011 2014-12-09 2014 198.01
M0022 2014-03-26 2014 12.81
M0022 2014-04-01 2014 78.99
M0002 2015-07-08 2015 12.81
M0001 2016-06-15 2016 6.71
M0003 2015-08-13 2015 24.31
M0001 2016-06-08 2016 36.91
M0022 2016-02-02 2016 1009.02
M0002 2015-04-19 2015 88.93
M0013 2015-03-06 2015 16.8
M0002 2016-01-05 2016 19.21
M0002 2016-02-26 2016 38
M0002 2016-03-17 2016 16.91

and we want to sum up all values in column 4 for same values in column 1, so we can use the following script:

awk '{sum[$1] += $4}
END {for( i in sum) print i, sum[i]}'

The SHEXEC function call put out:

M0001 43.62
M0002 198.16
M0003 24.31
M0022 1100.82
M0011 198.01
M0013 16.8

Example 4:
Assumed, that the script variable $STDIN contains the following text:

scale=0
p[1]=2
n=1
define p(x){
pz=1
for(z=1;z<=sqrt(n);z++){
if(x % p[z] == 0){
pz=0;
break;
}
}
p[++n]=x;
return(pz)
}
p[1]
for(i=3;i<=$1;i+=2){
if( p(i) ) i
}

the function call SHEXEC("bc -l";$STDIN;15013) returns a list of all prime numbers from 2 to 15013.

Example 5:
For a list like $INPUT from Example 3, containing multiple columns, the call
SHEXEC("awk -v COL=$1 '{print $COL}' ";$INPUT;n) where n is a column number (from 1 to 4) generates a list with only the selected column.


For more informations see also the manuals of the mentioned commands (bc, sort, sed, awk ).
The following script opens a pdf-file with a command description. Specify the command name (e.g. awk) as first parameter.

test "$1" && { man -t $1 | pstopdf -i -o /tmp/$1.pdf ; open /tmp/$1.pdf ;} || echo parameter missing '(command)'

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

There are no comments yet. Be the first to post a comment about this Custom Function! Please try to keep it brief & to the point. Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 6 + 4 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. TimeFormatAsText ( theTime )
  (Mon, Nov 13, 1:59pm)
2. ParseWebValueList( text )
  (Thu, Nov 02, 9:52am)
3. SVG_HTML_to_Text ( _svg_text ; _orig_text ;
  (Wed, Oct 25, 4:17am)
4. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
5. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
6. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
7. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
8. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)

RSS Feed of Custom Functions