Finally found a solution thanks to two things that have changed since I originally posted this 5 years ago: (0.) Have since migrated to macOS ‘Ventura’ after my previous 2010 MacBook Pro broke down; and (1.) I didn’t have Claude AI around back in 2021 to find the following solution for me:
Claude.ai’s solution using Automator:
In Automator, select Quick Action;
With “Workflow receives current” set to Automatic (text) by default, and with “in” set to Any application by default, select Output replaces selected text;
Add (drag) Run Shell Script to the workflow;
With “Shell:” set to your desired shell (/bin/ksh in my case), and with “Pass input:” set to to stdin by default, replace the default “cat” with the name of your external filter (in my case “f”) [note: make sure your PATH in your desired shell includes the directory containing your filter (in my case f); otherwise you’ll have to specify the absolute path to your external filter]; and
Save your Automator action, and “Save quick action as:” whatever (in my case, I used “f,” in spite of the lowercase name not following Apple’s convention of having all menu items have initial caps).
You should now be able to invoke your external filter by selecting text in Xcode and going to Xcode ⇀ Services ⇀ f (or whatever the name of your external filter is).
Assigning a keyboard shortcut to run f (or whatever your external filter is):
Go to System Settings ⇀ Keyboard ⇀ Keyboard Shortcuts…;
In the sidebar select Services;
Expand/explode the “Text” line, and to the right of f (or whatever the name of your external filter/Automator quick action is), double-click on “none”;
Type your preferred keyboard shortcut to run your external filter (in my case I used option-F to run my f, because command-F was already used by Xcode for “Find…,” shift-command-F was already used by Xcode for “Find in Workspace…,” option-command-F was already used by Xcode for “Find and Replace…,” and control-command-F was already used by Xcode for “Enter Full Screen”).
You should now be able to invoke your external filter on selected text from within Xcode using your preferred keyboard shortcut (option-F in my case).
Tested all the above in Xcode 15.2 under macOS “Ventura” version 13.7.8.
H/t Claude AI for figuring out all the above for me; I was this close to throwing up my hands and migrating to Sublime Text (which I’ve been procrastinating doing for five years due to Sublime Text’s poor/nonexistent rendering support for RTL languages such as Hebrew and Arabic, something whereat Xcode excels)
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: