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...
Lot of other uses for macOS Service > search_and_replace
onrun {input} set search_string to "~" set replace_string to "$$"
set text_after to search_and_replace(input asstring, search_string, replace_string) return text_after endrun
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 toeverytext itemof text_before set AppleScript's text item delimiters to replace_string set text_after to text_items asstring
set AppleScript's text item delimiters to current_delims return text_after end search_and_replace
@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.
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?
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.
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:
In your FileMaker script, select all steps.
Copy those steps to the clipboard.
Run "fmClip - Replace String in FM Objects.applescript"
Use the old variable (I recommend including the $, for reasons I'll explain below) as the SearchFor string.
When it asks for the Replace With string, type in your new variable name (make sure to include the $ symbol, again).
Back in your FileMaker script, delete the selected steps.
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.
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;""))
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.)
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.