This is a known problem with automator services that have AppleScript actions in them. I suppose Gatekeeper doesn't like them because it looks like code injection.
The workaround (until Apple does something to fix the problem) is to take the AppleScript in your action and turn it into a stand-alone AppleScript application: copy the code into Script Editor and save the file, choosing Application from the File Format menu. Add this script app to the Accessibility Security pane — System Preferences->Security & Privacy->Privacy->Accessibility — and it should pass GateKeeper's muster. Then you have a choice, depending on your setup:
- Create a Quick Action in Automator that calls the app.
Create a Quick Action as normal, and use the Launch Application action to run the script app. This should work as a service or as a Quick Action in the Finder preview pane
- Turn the script app into a service in its own right.
In the Finder, find the script app, then select "Show Package Contents" from the contextual menu. Drill down to the file "info.plist", open it in a plain-text editor and edit in a new key-value unit that looks like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
[...]
<key>NSServices</key>
<array>
<dict>
<key>NSBackgroundColorName</key>
<string>background</string>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>Service Name</string>
</dict>
<key>NSMessage</key>
<string>run</string>
</dict>
</array>
</dict>
</plist>
... making sure not to delete or damage any of the default xml that Script Editor generates for script apps. Save the revised info.plist file, place the script app in ~/Library/Services. This only seems to work as a service (I can't get them to show up in the Extensions preference pane).