I have a Google Translate app created with Fluid App. I want to translate any selected text with this my Google Translate Fluid App.
So, for this purpose how do I create a service with Automator/AppleScript?
Here is the AppleScript code I use in a Run AppleScript action, in an Automator Service workflow in conjunction with my Google Translate Fluid App, which is named Google Translate.
Create an Automator Service workflow with the settings as shown in the image below, while replacing the default AppleScript code with the AppleScript code found below the Automator image. Note that I saved it as Translate with Google Translate and this is what shows on the Services menu and context menu when I have selected text that I want to translate.
The use of
do shell script "open -a " ... is necessary because a Fluid App with default Preferences, one created with Fluid, by default when opened from the macOS UI shows its Home Page. However, when programmatically opened via AppleScript, example case,
tell application "Google Translate" to activate, only the Dock Tile appears, no
browser window, i.e. no Home Page is displayed. This is in part why I originally coded it the way I did. However, since your comment, I found out that if I programmatically opened via AppleScript using
do shell script "open -a " ..., it opens with a browser window, not just the Dock Tile and as such was able to recode the Service differently because the use of
do shell script "open -a " ... also would bring a minimize window back up without the need to account for that with additional coding.
Hopefully the new code will eliminate two Google Translate tabs from appearing when starting from a closed state. (Although depending on timings, it may occasionally happen.)