Skip to content

Commit 11889fe

Browse files
committedJul 24, 2012
Periodic push of generic updates.
1 parent 1f7a867 commit 11889fe

17 files changed

+233
-54
lines changed
 

‎AppleScriptLDAPLookup.calc

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
Let ( [
2+
fullName = TextEncodeForAppleScript ( TextEncodeUTF8Hex ( fullName ) ) ;
3+
noResultMessage = "Error: No matches found" ;
4+
db = Get ( FileName ) ;
5+
fieldList = Substitute ( resultFieldName ; "::" ; ¶ ) ;
6+
table = GetValue ( fieldList ; 1 ) ;
7+
field = GetValue ( fieldList ; 2 ) ;
8+
fmpVersion = "FileMaker Pro" & If ( Position ( Get ( ApplicationVersion ) ; "ProAdvanced" ; 1 ; 1 ) ; " Advanced" ) ;
9+
searchString = If ( IsEmpty ( valueToReturn ) ; "" ; " cn " & valueToReturn )
10+
] ;
11+
"set DSID to \"" & DSID & "\"¶
12+
set name_full to \"" & fullName & "\"¶
13+
set db to \"" & db & "\"¶
14+
set tableName to \"" & table & "\"¶
15+
set fieldName to \"" & field & "\"¶
16+
set noResultMessage to \"" & noResultMessage & "\"¶
17+
set valueToReturn to \"" & valueToReturn & "\"¶
18+
19+
if DSID ≠ \"\" then¶
20+
set shell_script to \"ldapsearch -b 'ou=people,o=Apple Computer' -h ldap.apple.com -x -u -LLL '(DSID=\" & DSID & \")'" & searchString & "\"¶
21+
else if ((offset of \" \" in name_full) as number is greater than 0) then¶
22+
set shell_script to \"ldapsearch -b 'ou=people,o=Apple Computer' -h ldap.apple.com -x -u -LLL '(cn=\" & name_full & \")'" & searchString & "\"¶
23+
else¶
24+
set shell_script to \"ldapsearch -b 'ou=people,o=Apple Computer' -h ldap.apple.com -x -u -LLL '(sn=\" & name_full & \")'" & searchString & "\"¶
25+
end if¶
26+
27+
if valueToReturn ≠ \"\" then¶
28+
set shell_script to shell_script & \" \" & valueToReturn¶
29+
end if¶
30+
31+
try¶
32+
set ldapResult to do shell script shell_script as text¶
33+
on error errText number errNum¶
34+
set ldapResult to errNum & \": \" & errText & \". \" & ldapResult¶
35+
setField(db, tableName, fieldName, ldapResult)¶
36+
return¶
37+
end try¶
38+
39+
if ldapResult = \"\" then¶
40+
set myResult to noResultMessage¶
41+
else¶
42+
set ldapResultElement_count to patternCount(ldapResult, \"dn\")¶
43+
set myResult to ldapResult¶
44+
end if¶
45+
46+
setField(db, tableName, fieldName, myResult)¶
47+
48+
------------------------------------------------¶
49+
-- HANDLERS¶
50+
------------------------------------------------¶
51+
52+
--Handler: Returns value of first matching ldap result element¶
53+
on ldapResultElement(resultText, elementName)¶
54+
set elementStart to offset of elementName as text in resultText¶
55+
if (elementStart) > 0 then¶
56+
set myResult to text (elementStart + (length of elementName) + 2) through ((length of resultText) - 1) of resultText¶
57+
end if¶
58+
end ldapResultElement¶
59+
60+
--Handler: Returns patterncount¶
61+
on patternCount(theText, matchString)¶
62+
set oldTID to AppleScript's text item delimiters¶
63+
set AppleScript's text item delimiters to {matchString}¶
64+
set countedPattern to count of text items of theText¶
65+
set AppleScript's text item delimiters to oldTID¶
66+
return countedPattern - 1¶
67+
end patternCount¶
68+
69+
--Handler: Sets FileMaker field value¶
70+
on setField(databaseName, tableName, fieldName, theValue)¶
71+
tell application " & Quote ( fmpVersion ) & "¶
72+
tell database (databaseName as text)¶
73+
tell table (tableName as text)¶
74+
set field fieldName to theValue¶
75+
end tell¶
76+
end tell¶
77+
end tell¶
78+
end setField"
79+
)
80+
81+
/* —————————————————————————————— //
82+
NAME:
83+
AppleScriptLDAPLookup ( DSID ; fullName ; resultFieldName ; valueToReturn )
84+
85+
PURPOSE:
86+
Returns record from LDAP server.
87+
Searches by fullName if DSID is not specified.
88+
Returns full LDAP record if valueToReturn is not specified.
89+
90+
EXAMPLES:
91+
AppleScriptLDAPLookup ( "1337626871" ;
92+
"" ;
93+
GetFieldName ( GLOBAL::TEMP_TEXT_GT ) ;
94+
"cn"
95+
) // returns name of person
96+
97+
HISTORY:
98+
Created: 2011-Mar-15 15h21 PST — Donovan A. Chandler
99+
*/

‎CodeMerge.calc

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Let ( [
1010
//-- Don't leave label in place if it isn't recognized, to prevent open loop
1111
code =
1212
Case (
13-
markerType = "CODE" ; FOCUS::CODE_INCLUDE_REP[index] ;
14-
markerType = "CODE_LINK" ; FOCUS::CODE_LINK_REP[index] ;
15-
markerType = "CODE_NAME" ; FOCUS::CODE_FILE_NAME_REP[index] ;
13+
markerType = "CODE" or markerType = "*CODE" ; FOCUS::CODE_INCLUDE_REP[index] ;
14+
markerType = "CODE_LINK" or markerType = "*CODE_LINK" ; FOCUS::CODE_LINK_REP[index] ;
15+
markerType = "CODE_NAME" or markerType = "*CODE_NAME" ; FOCUS::CODE_FILE_NAMESPACE[index] & FOCUS::CODE_FILE_NAME_REP[index] ;
1616
"INVALID CODE LABEL: " & Substitute ( marker ; delim ; delim & " " )
1717
) ;
1818
textNew =

‎CodeMergeLinks.calc

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Let ( [
2+
linked = CodeMerge ( Substitute ( text ; "‡‡CODE[" ; "‡‡CODE_LINK[" ) )
3+
] ;
4+
CodeMerge ( Substitute ( linked ; "‡‡*CODE[" ; "‡‡CODE[" ) )
5+
)
6+
7+
/* __________________________________________________
8+
9+
NAME: CodeMergeLinks ( text )
10+
PURPOSE: Merges value from LIBRARY_CODE table into text,
11+
ensuring that links to values are included instead of merging in entire text.
12+
Useful when exporting code from a table.
13+
EXAMPLES:
14+
// Where FOCUS::LIBRARY_CODE_INCLUDE[index] = "Beezwax!"
15+
// Where FOCUS::LIBRARY_CODE_LINK[index] = "http://beezwax.net"
16+
CodeMergeLoop ( "Hello ‡‡CODE[1]‡‡" ) = "http://beezwax.net"
17+
CodeMergeLoop ( "Hello ‡‡CODE_LINK[1]‡‡" ) = "http://beezwax.net"
18+
19+
HISTORY:
20+
Created: 2012-06-21 12:14 PT - Donovan Chandler
21+
Modified:
22+
*/

‎ListAddOrRemove.calc

+17-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Let ( [
22
searchList = ¶ & currentList & ¶ ;
3-
value_exists = PatternCount ( searchList ; ¶ & value & ¶ ) ;
4-
currentListLength = Length ( currentList )
3+
value_exists = Position ( searchList ; ¶ & value & ¶ ; 1 ; 1 )
54
];
65
Case (
76
value_exists ;
@@ -12,40 +11,31 @@ Let ( [
1211
[ "|" & value & ¶ ; "" ];
1312
[ "¶|" ; ¶ ]
1413
)
15-
];
16-
Middle (
17-
newList ;
18-
2 ;
19-
Length ( newList ) - 2
20-
)
14+
];
15+
Middle ( newList ; 2 ; Length ( newList ) - 2 )
2116
) ;
2217

2318
IsEmpty ( value ) ;
2419
currentList ;
2520

26-
currentList &
27-
If ( Right ( currentList ; 1 ) ≠ ¶ and currentListLength ; ¶ ) & value
21+
List ( currentList ; value )
2822
)
2923
)
3024

31-
/* —————————————————————————————— //
32-
NAME:
33-
ListAddRemove ( currentList ; value )
34-
35-
PURPOSE:
36-
Adds or removes value from return-delimited list.
25+
/* __________________________________________________
3726

27+
NAME: ListAddOrRemove ( currentList ; value )
28+
PURPOSE: Adds or removes value from return-delimited list. Useful for adding/removing an id from a multi-key, such as for portal selections.
29+
EXAMPLES:
30+
ListAddRemove ( "foo" ; "fum" ) = "foo¶fum"
31+
ListAddRemove ( "foo¶fum" ; "foo" ) = "fum"
32+
ListAddRemove ( "foo¶¶fum" ; "foo" ) = "fum¶"
33+
ListAddRemove ( "foo¶fum" ; "foo¶fum" ) = "fum¶fum"
3834
HISTORY:
39-
Created: 2011-Mar-02 12h19 PST — Donovan Chandler
40-
Based on old function by Matt Petrowsky of ISO Productions, Inc.
41-
42-
INPUT:
43-
currentList: return-delimited list of values
44-
value: text string to be added or removed
45-
46-
OUTPUT:
47-
Return-delimited list from currentList parameter with value added or removed
48-
35+
Created: 2012-06-11 12:05 PT - Donovan Chandler based on function by Matt Petrowsky
36+
Modified:
4937
NOTES:
50-
Adds if "value" exists in "currentList" or removes if it does not. Useful for adding/removing an id from a multi-key, such as for portal selections.
38+
Does NOT remove any blank lines except for leading lines.
39+
Does NOT support multi-line strings in "value" parameter.
40+
NOT optimized for large lists. (Would need to get rid of substitutions.)
5141
*/

‎LogAdd.calc

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ Let ( [
5252

5353
)
5454

55-
/*
56-
NAME: AuditLog ( logText ; fieldsToLog ; format ; separator ; id )
57-
PURPOSE: This custom function is called in an auto-enter text field so that every field listed as a parameter for this function automatically triggers the field to update. This function merely collects a snapshot of the related information and formats it for presentation.
58-
EXAMPLE:
55+
/* __________________________________________________
56+
57+
NAME: LogAdd ( logText ; fieldsToLog ; format ; separator ; id )
58+
PURPOSE: Called in an auto-enter text field so that every field listed as a parameter for this function automatically triggers the field to update. This function merely collects a snapshot of the related information and formats it for presentation.
59+
EXAMPLES:
5960
AuditLog ( AuditLog ; Name & Company ; "%Date%Time%Account$Key%Field%Change" ; " " )
6061
NOTES:
6162
If you separate the values with a reliable delimiter like "|", then you can have a separate table parse out the values. To do this, place the log entries into a global field that automatically extracts the first line every time it's updated. Take that first line and split it into a value list, having different fields grab their relative value every time a new record is created.

‎PathForImport.calc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Let([ win = Abs ( Get ( SystemPlatform ) ) = 2 ; slash = If ( win ; "\\" ; "/" ) ; //-- Remove prefixes posColon = Position ( path ; ":" ; 1 ; 1 ) ; path = If ( posColon = 0 ; path ; Middle ( path ; posColon + 1 ; 999 ) ) ; path = If ( Left ( path ; 1 ) ≠ slash ; slash ) & path ; //-- Add system drive disk = Substitute ( Get ( SystemDrive ) ; "/" ; "" ) ; path = If ( Position ( path ; disk ; 1 ; 1 ) = 0 ; slash & disk ) & path ; //-- Add 'Volumes' for mounted disks //path = If ( mac ; "/Volumes" & path ) //-- Add prefix prefix = If ( win ; "filewin:" ; "filemac:" ) ] ; Case ( IsEmpty ( path ) ; "" ; prefix & path ))/* __________________________________________________NAME: PathForImport ( path )PURPOSE: Modifies path to conform to FileMaker's expectations for imports, etc.EXAMPLES: PathForImport ( "/Macintosh HD/Users/Admin/Desktop/text.txt" ) // (Mac OS) = "filemac:/Macintosh HD/Users/Admin/Desktop/text.txt" // (Windows) = "filewin:\Macintosh HD\Users\Admin\Desktop\text.txt"HISTORY: Created: 2012-02-12 PST -07 09h50 PST — Donovan Chandler*/
1+
Let([ win = Abs ( Get ( SystemPlatform ) ) = 2 ; slash = If ( Position ( Get ( DesktopPath ) ; "/" ; 1 ; 1 ) ; "/" ; "\\" ) ; //-- Remove prefixes // Use PathStripPrefix. Don't strip "C:" portion of path in windows. posColon = Position ( path ; ":" ; 1 ; 1 ) ; path = If ( posColon = 0 ; path ; Middle ( path ; posColon + 1 ; 999 ) ) ; path = If ( Left ( path ; 1 ) ≠ slash ; slash ) & path ; //-- Add system drive disk = Substitute ( Get ( SystemDrive ) ; "/" ; "" ) ; path = If ( Position ( path ; disk ; 1 ; 1 ) = 0 ; slash & disk ) & path ; //-- Add 'Volumes' for mounted disks //path = If ( mac ; "/Volumes" & path ) //-- Add prefix prefix = If ( win ; "" /*"filewin:"*/ ; "filemac:" ) ] ; Case ( IsEmpty ( path ) ; "" ; prefix & path ))/* __________________________________________________NAME: PathForImport ( path )PURPOSE: Modifies path to conform to FileMaker's expectations for imports, etc.EXAMPLES: PathForImport ( "/Macintosh HD/Users/Admin/Desktop/text.txt" ) // (Mac OS) = "filemac:/Macintosh HD/Users/Admin/Desktop/text.txt" // (Windows) = "\Macintosh HD\Users\Admin\Desktop\text.txt"HISTORY: Created: 2012-02-12 PST -07 09h50 PST — Donovan Chandler*/
+5-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
Let ( [
2-
isMac = Abs ( Get ( SystemPlatform ) ) = 1
3-
; pathPlain = FilePathStripPrefix ( path )
4-
; prefix = "file://" & If ( isMac ; "/Volumes" )
2+
isMac = Abs ( Get ( SystemPlatform ) ) = 1 ;
3+
pathPlain = PathStripPrefix ( path ) ;
4+
prefix = "file://" & If ( isMac ; "/Volumes/" )
55
] ;
66
prefix & pathPlain
77
)
88

99
/* __________________________________________________
1010

11-
NAME: FilePathForWebViewer ( path )
11+
NAME: PathForWebViewer ( path )
1212
PURPOSE: Encodes file path for use in web viewer.
1313
EXAMPLES:
1414

1515
NOTES:
1616
On Mac, prepend with "file:///Volumes/"
1717
On Win, prepend with "file:///"
1818
HISTORY:
19-
Created: 2010-06-23 16:39 PST - Donovan A. Chandler
19+
Created: 2010-06-23 16:39 PT - Donovan A. Chandler
2020
*/

‎SQLField.calc

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ Let ( [
1313
NAME: SQLField ( field )
1414
PURPOSE: Returns name of field for use in SQL statements. Accepts field or name of field.
1515
EXAMPLES:
16+
SQLField ( GetFieldName ( CONTACT::Name ) ) = "contact.\"name\""
17+
SQLField ( CONTACT::Name ) = "contact.\"name\""
1618
SQLField ( "CONTACT::Name" ) = "contact.\"name\""
17-
SQLField ( GetFieldName ( CONTACT::Name" ) ) = "contact.\"name\""
1819
HISTORY:
1920
Created: 2011-11-04 16:45 PST - Donovan Chandler
2021
Modified: 2011-11-28 14:20 PST - Donovan Chandler ; added support for field name if reference fails; also returns field name of no table is provided

‎ScriptTraceAdd.calc

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ EXAMPLES:
1414
NOTES:
1515
Valid action values: {start, end, debug, error}
1616
HISTORY:
17-
Created: 2011-04-26 14:58 PST - Donovan A. Chandler
18-
*/
17+
Created: 2011-04-26 14:58 PST - Donovan Chandler
18+
*/

‎ScriptTraceOff.calc

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ PURPOSE: Sets global flag to ensure scripts are NOT permitted to build trace log
1111
HISTORY:
1212
Created: 2012-04-11 11:27 PST - Donovan Chandler
1313
Modified:
14-
*/
14+
*/

‎TimestampMicro.calc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FmNexUt_GetTimestampMicro(1)
1+
FmNexIns_GetTimestampMicro(1)
22

33
/* __________________________________________________
44

‎TrimCR.calc

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Let ( [
2-
cleanString = Substitute ( text ; [ ¶ ; "" ] ; [ Char ( 10 ) ; "" ] ; [ " " ; "" ] ; [ Char ( 9 ) ; "" ] ) ;
2+
cleanString = Substitute ( text ; ¶ ; "" ) ;
33
first = Left ( cleanString ; 1 ) ;
44
leftPosition = Position ( text ; first ; 1 ; 1 ) ;
55
last = Right ( cleanString ; 1 ) ;
@@ -12,8 +12,8 @@ Let ( [
1212

1313
/* __________________________________________________
1414

15-
NAME: TrimWhitespace ( text )
16-
PURPOSE: Removes leading and trailing whitespace from text.
15+
NAME: TrimCR ( text )
16+
PURPOSE: Removes leading and trailing carriage returns from text.
1717
EXAMPLES:
1818
TrimCR ( "¶¶text¶" ) = "text"
1919
NOTES:
@@ -24,5 +24,4 @@ HISTORY:
2424
Created: 2010-10-21 12:00 PST - Salvatore Colangelo
2525
Modifed: 2010-11-07 12:12 PST - Will M. Baker ; slight modifications to Salvatore's solution to bring in line with our naming conventions.
2626
Modified: 2012-01-10 10:34 PST - Donovan Chandler ; updated comments and removed sample of Will's previous version.
27-
Modified: 2012-04-18 12:18 PST - Donovan Chandler ; now removes other whitespace
2827
*/

‎TrimWhitespace.calc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Let ( [
2-
cleanString = Substitute ( text ; ¶ ; "" ) ;
2+
cleanString = Substitute ( text ; [ ¶ ; "" ] ; [ Char ( 10 ) ; "" ] ; [ " " ; "" ] ; [ Char ( 9 ) ; "" ] ) ;
33
first = Left ( cleanString ; 1 ) ;
44
leftPosition = Position ( text ; first ; 1 ; 1 ) ;
55
last = Right ( cleanString ; 1 ) ;
@@ -12,8 +12,8 @@ Let ( [
1212

1313
/* __________________________________________________
1414

15-
NAME: TrimCR ( text )
16-
PURPOSE: Removes leading and trailing carriage returns from text.
15+
NAME: TrimWhitespace ( text )
16+
PURPOSE: Removes leading and trailing whitespace from text.
1717
EXAMPLES:
1818
TrimCR ( "¶¶text¶" ) = "text"
1919
NOTES:
@@ -24,4 +24,5 @@ HISTORY:
2424
Created: 2010-10-21 12:00 PST - Salvatore Colangelo
2525
Modifed: 2010-11-07 12:12 PST - Will M. Baker ; slight modifications to Salvatore's solution to bring in line with our naming conventions.
2626
Modified: 2012-01-10 10:34 PST - Donovan Chandler ; updated comments and removed sample of Will's previous version.
27+
Modified: 2012-04-18 12:18 PST - Donovan Chandler ; now removes other whitespace
2728
*/

‎URLDecoded.calc

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Substitute (
2+
text ;
3+
[ "%25" ; "%" ] ;
4+
[ "%0D" ; "¶" ] ;
5+
[ "%20" ; " " ] ;
6+
[ "%21" ; "!" ] ;
7+
[ "%22" ; "\"" ] ;
8+
[ "%23" ; "#" ] ;
9+
[ "%24" ; "$" ] ;
10+
[ "%26" ; "&" ] ;
11+
[ "%27" ; "'" ] ;
12+
[ "%28" ; "(" ] ;
13+
[ "%29" ; ")" ] ;
14+
[ "%2A" ; "*" ] ;
15+
[ "%2B" ; "+" ] ;
16+
[ "%2C" ; "," ] ;
17+
[ "%2D" ; "-" ] ;
18+
[ "%2E" ; "." ] ;
19+
[ "%2F" ; "/" ] ;
20+
[ "%3A" ; ":" ] ;
21+
[ "%3B" ; ";" ] ;
22+
[ "%3C" ; "<" ] ;
23+
[ "%3D" ; "=" ] ;
24+
[ "%3E" ; ">" ] ;
25+
[ "%3F" ; "?" ] ;
26+
[ "%40" ; "@" ] ;
27+
[ "%5B" ; "[" ] ;
28+
[ "%5C" ; "\\" ] ;
29+
[ "%5D" ; "]" ] ;
30+
[ "%5E" ; "^" ] ;
31+
[ "%60" ; "`" ] ;
32+
[ "%7B" ; "{" ] ;
33+
[ "%7C" ; "|" ] ;
34+
[ "%7D" ; "}" ]
35+
)
36+
37+
/* __________________________________________________
38+
39+
NAME: URLDecoded ( text )
40+
PURPOSE: Reverse of GetAsURLEncoded( ). Converts url-encoded characters to regular strings.
41+
See http://ascii-code.com/ for full reference of ascii codes.
42+
EXAMPLES:
43+
URLDecoded ( "%7B%22foo%22:%2023%7D" ) = "{\"foo\": 23}"
44+
HISTORY:
45+
Created: Based on function by Jeremiah Small, http://www.briandunning.com/cf/528
46+
Modified: 2012-06-21 13:58 PT - Donovan Chandler
47+
*/

‎URLHash.calc

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Middle ( url ; Position ( url ; "#" ; 1 ; 1 ) ; Length ( url ) )
1+
Let ( [
2+
pos = Position ( url ; "#" ; 1 ; 1 )
3+
] ;
4+
If (
5+
pos > 0 ; Middle ( url ; pos ; Length ( url ) )
6+
)
7+
)
28

39
/* __________________________________________________
410

‎URLParam.calc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
TextBetween ( url & "&" ; name & "=" ; "&" ; 1 )
2+
3+
/* __________________________________________________
4+
5+
NAME: URLParam ( url ; name )
6+
PURPOSE: Retrieves parameter value from url.
7+
Doesn't parse or decode full url because OnTimer script usually handles that.
8+
EXAMPLES:
9+
URLParam ( "http://domain.com#animal=dog&food=donuts%20" ; "food" ) = "donuts%20"
10+
HISTORY:
11+
Created: 2012-06-21 16:00 PST - Donovan Chandler
12+
Modified:
13+
*/

‎UserIsFullAccess.calc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Get ( AccountPrivilegeSetName ) = "[Full Access]"
22

33
/* __________________________________________________
44

5-
NAME: UserIsFullAccess
5+
NAME: UserIsFullAccess ( )
66
PURPOSE: Returns True if user has full access privileges
77
HISTORY:
88
Created: 2012-09-12 PST -27 16h16 PST — Donovan A. Chandler

0 commit comments

Comments
 (0)
Please sign in to comment.