macOS Services to help write FileMaker code

You can use macOS Services (built with Automator.app) to help write FileMaker code.
(There are many good posts on the internet on what macOS Services are and how they work.)
Files go in the ~/Library/Services/ folder.
Use at you own risk!

You can see a movie with the 2 examples (shown and downloadable below) in this tweet...

FM_Grey_8_wrap_string_2020-08-20.workflow download

FM_Bold_wrap_string_2020-08-20.workflow download
image

What other macOS Services would be helpful in writing FileMaker code?

1 Like

Nice idea.

I use text shortcuts via the Keyboard->Text prefs pane. The one I use most often is "exitloop", which expands to "let($i = $i+1; $i > $n)".

Could your method place a complete clipping of script steps onto the clipboard or paste it into the script workspace? In this example I'd use

Set Variable [ $n ; Get( FoundCount ) ]
Set Variable [ $i ; 0 ]
Loop
Exit Loop If [ let($i = $i+1; $i > $n)  ]
...
Exit Loop

Thank you.

Pasting in "a complete clipping of script steps" is a different tool/technique.

We used to sell a tool that we call Script Building Blocks...
http://www.twdesigns.com/products/index.php
..that allowed pasting in "a complete clipping of script steps".

We would bring a more modern version of Script Building Blocks (and its siblings) back to market if there was enough interest.

Not sure what is currently available in the "a complete clipping of script steps" market?

In the meantime, macOS services are free!

Hope that helps.

Geist's Generator is free also. You can create your own "Generators". :slight_smile: karbonfm/karbon_Generator.fmp12 at 74cd1956f53f18cd583ec92b7d70565cb526a138 · karbonfm/karbonfm · GitHub

1 Like

Have you seen the extensions you can define yourself for Script Workspace?

3 Likes

If you are using ~ as the Let vars prefix, these 2 .workflows can help debugging.

1/2

2/2

Lot of other uses for macOS Service > search_and_replace

on run {input}
set search_string to "~"
set replace_string to "$$"

set text_after to search_and_replace(input as string, search_string, replace_string)
return text_after
end run

on search_and_replace(text_before, search_string, replace_string)
set current_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to search_string
set text_items to every text item of text_before
set AppleScript's text item delimiters to replace_string
set text_after to text_items as string

set AppleScript's text item delimiters to current_delims
return text_after
end search_and_replace

4 Likes

Another set of free code is FmClipTools, which is found at GitHub - DanShockley/FmClipTools: Tools for converting, modifying, and saving FileMaker Pro clipboard objects. Coded in AppleScript.
Disclaimer: I built most of this, and hope people find it useful.

7 Likes

@DanShockley thanks so much for your work on FMClipTools. It's, by far, the tool I use most, and I'm not even sure I could stand to use FileMaker without them anymore. I also know first-hand multiple other people who use them.

I quietly evangelize about your library whenever I get the chance.

Not sure I've ever thanked you directly, but you've really revolutionized the way I work.

4 Likes

That's good to hear! Thanks for the encouragement. I enjoy building things that make other people's lives easier.

2 Likes

I've just downloaded them and installed them in the "no third-party" configuration. I'm not getting anything back when I run them. I do see the gear cog appear in the menu momentarily.

Is there a trick that beginners need to learn, or am I just doing it wrong?

Mac OS Big Sur FMP 19.4

I can't comment on "no-third party" configuration, but IMHO a third party tool like TextExpander/Typinator really enhances FMClipTools. This video desperately needs a re-record (I didn't originally intend it for public), but it shows some of the potential and how to start integrating it with TextExpander.

1 Like

If they worked properly, most of those AppleScripts won't display anything, they just modify the clipboard.
For example, the file "fmClip - Clipboard FM Objects to XML.applescript" just modifies the clipboard so that it contains the text (XML) representation of whatever FileMaker objects you just copied into the clipboard.
So, if you go into a FileMaker script, copy a few script steps (or a whole script, or multiple scripts), then run that AppleScript from the Scripts menu in the menubar, your clipboard will now (also) contains text XML that you can paste into a text document.
Some of the AppleScripts DO present a simple interface. For example, if you run "fmClip - Replace String in FM Objects.applescript", it will ask you for a search string and then a replacement string, which it will then use to modify the FileMaker objects in the clipboard. You could use this to rename a variable in a FileMaker script:

  1. In your FileMaker script, select all steps.
  2. Copy those steps to the clipboard.
  3. Run "fmClip - Replace String in FM Objects.applescript"
  4. Use the old variable (I recommend including the $, for reasons I'll explain below) as the SearchFor string.
  5. When it asks for the Replace With string, type in your new variable name (make sure to include the $ symbol, again).
  6. Back in your FileMaker script, delete the selected steps.
  7. Paste the modified clipboard objects - wherever the old variable name was will now have the new variable name.

One IMPORTANT thing to know is that this replacement does not do any preservation of the XML infrastructure in the objects. So if, for example, you searched for "Field" and changed it to "Bartholomew", the objects in the clipboard would NOT be valid, and either wouldn't paste into FileMaker, or would paste broken/corrupted objects. I haven't tested what kinds of problems that could cause. So, as I suggested above, you really want to make sure you only SearchFor something that is yours, as in, VERY unlikely to be a string that would be contained in the rest of the XML.
If you want to do a more cautious search-and-replace, you could use "Clipboard FM Objects to XML", paste the result into a decent text editor like BBEdit or Sublime, search for the thing you want to change and make sure the only matches are the things you INTEND to change, then search-and-replace in the text editor. Then, you could copy the modified text and use "Clipboard XML to FM Objects" to convert back to FileMaker objects you can then paste back into FileMaker. That's more steps than the "Replace" AppleScript, but can help if you aren't yet sure what kinds of things the XML contains and you don't yet know what to avoid changing.

1 Like

Thanks for the explanations @DanShockley. It's working now, and I'm not sure what changed. I switched FMP off and on again.

I can imagine that doing replacements of TO names would be one of the first uses. Having checked the XML code that is produced I started thinking about how to ensure that I only act on the "correct" objects. Now all I can think of is Buster Keaton.

Hey, somebody elsenet suggested I post this here.
A couple of years ago I brought Debbie Fuchs's old PERL FM Calculation Formatter up to date with current FM syntax and packaged it as a MacOS System Service using an Automator workflow for easy availability within FileMaker or any other app. Available at https://github.com/kupietools/_format-FM-calc-automator-workflow. Now you can select any calculation text (even outside of FileMaker, in text editors, etc.) and in a single mouseclick convert it from this:

Let(textNoRangeMove=Substitute(alerts::full text display;["higher range, xu";"__"];["lower range, xo";"__"]); If((Position( position_prognosis_at_import ;"Bullish";1;1)>0 and Position (textNoRangeMove;" xu ";1;1)>0 ) or (Position( position_prognosis_at_import;"Bearish";1;1)>0 and Position (textNoRangeMove;" xo ";1;1)>0 );1;""))

to this:

Let (
     textNoRangeMove =
     Substitute (
          alerts::full text display ;
          [ "higher range, xu" ; "__" ] ;
          [ "lower range, xo" ; "__" ]
     ) ;
     If (
          (
               Position ( position_prognosis_at_import ; "Bullish" ; 1 ; 1 ) >
               0 and Position ( textNoRangeMove ; " xu " ; 1 ; 1 ) > 0
          ) or
          (
               Position ( position_prognosis_at_import ; "Bearish" ; 1 ; 1 ) >
               0 and Position ( textNoRangeMove ; " xo " ; 1 ; 1 ) > 0
          ) ;
          1 ;
          ""
     )
)
/* Formatted with _Format FM Calc.workflow. Service based on Calculation_formatter.pl © 2008 by Debi Fuchs <debi@aptworks.com> and released under the GNU license. Debugged, modified, updated, and repackaged as a service by Michael Kupietz <consulting-fmsvc@kupietz.com> https://kupietz.com. Updated again at tremendous risk and great personal expense for nicer formatting in 2017. Released under GNU license, see source code for details. Be excellent to each other. */

That credit block always appears at the end, but obviously you're free to just remove it, it's just a text comment. (edited)

3 Likes

Free version of MBS has a calculation beautifying tool

1 Like

Yes, please check our ƒ button in the calculation dialog: Goodies 37: Format button

or the SyntaxColoring.FormatCalculation function for calculations stored in fields. See our example files:

1 Like

Free version of MBS has a calculation beautifying tool

And nag screens. And isn't open source. And isn't a MacOS Service per the thread topic, so doesn't work outside of FIleMaker (like, in text editors or web forms.)

1 Like

no nag screen at all

1 Like

Hello and thank you for your offer @DanShockley. Is there any literature or online training offered how I could learn these promising tools?

1 Like

There isn't any real training for using this, although there are some videos out there. Matt Petrowsky did a video on YouTube for ISO FileMaker Magazine showing how to use FmClipTools with a product called BetterTouchTool to easily work with FileMaker objects: https://www.youtube.com/watch?v=oqj12X85zIg
That includes a bunch of examples of how/why you might want to use something like this. You could manually do (at least some of ) the steps that BTT does yourself by copying an object, then running the FmClipTools "fmClip - Clipboard FM Objects to XML.applescript" script from the AppleScript menu. But, it's often really helpful to get a macro utility like BetterTouchTool, Keyboard Maestro, or Raycast, when it comes to running the various scripts included in the (free) FmClipTools.

1 Like