Some Custom Functions to Share

Here are a few custom functions I have used in the past that may be useful to others. The first is a rather robust function that gathers all instances of a file or folder and lists them in chronological order. It uses a shellscript( using mdfind and gets the list of file paths then an arrayfilter( adds on the superdate of the last date modified for each database path followed by an arraynumericsort( to get them in chronological order with a final arrayfilter to convert the superdate to a text pattern for date and time modified. A file name must include the extension but there is no need to match the case for a file or folder name.

registercustomfunction "LOCATEFILES",1,{arrayfilter(arraynumericsort(arrayfilter(shellscript(
||| mdfind "kMDItemFSName='|||+?(•1="",info("databasefilename"),•1)+|||'"|||)
,cr(),||| superdate(val(nthline(fileinfo(import()),5)),
val(nthline(fileinfo(import()),6)))+tab()+import() |||),cr()),cr(),
|||superdatestr(val(arrayfirst(import(),tab())))+tab()+arraylast(import(),tab()) |||)}

In use:

let x= locatefiles("Logo.gif")

Returns this on my computer:>

11/17/03 12:43 PM /Users/garyyonaites/Documents/Archive/Pratchettes Help/Logo.gif
10/19/04 6:49 AM /Users/garyyonaites/Documents/Archive/Documents/PratchettesX/Logo.gif
10/19/04 6:49 AM /Users/garyyonaites/Documents/Archive/Pratchettes Archive/Logo.gif
10/19/04 6:49 AM /Users/garyyonaites/Documents/unseensoft.com/PratchettesX/Logo.gif
10/22/04 1:41 PM /Users/Shared/Previously Relocated Items/Security/Pratchettes Help/Logo.gif
10/22/04 1:41 PM /Volumes/Alt SSD/Users/Shared/Security/Pratchettes Help/Logo.gif
11/21/18 10:23 AM /Users/garyyonaites/Documents/Logo.gif
11/21/18 10:23 AM /Users/garyyonaites/iCloud Drive (Archive)/Documents/Logo.gif

Here are two additional simple custom functions that will get either the maximum or minimum number from a text array of numeric values.

ArrayNumericMax:

registercustomfunction "ARRAYNUMERICMAX",2,||| arraylast(arraynumericsort(•1,•2),•2) |||

ArrayNumericMin:

registercustomfunction "ARRAYNUMERICMIN",2,||| arrayfirst(arraynumericsort(•1,•2),•2) |||
2 Likes

Thank you Gary. Are these also posted in the Software Exchange or do we just copy them from here?

What I have shown is the code to create and register the functions (they are not on the Panorama Database Exchange). If you run the code listed in an .Initialize or a separate procedure they will be available to any database until Panorama X quits. If you want them always available anytime Panorama X is started you need to add them to your personal library file. Instruction for this can be found elsewhere on this forum.

I keep code like this in a Panorama file with three fields, the name of the procedure or code, the code itself, and notes about the code. It is a handy way to keep track of things you may need in the future, even if you are not using it now.