The issue with your approach is that you said to make something in Automator. THIS is what takes Ruby out of the equation. An Automator Quick Action in Launchbar means the script itself is run. As standalone. So there is no governing script that integrates Ruby at all. A master governing Ruby script can implement AppleScript through the syntax that I posted.
I see what you did by shoving the (either Launchbar or Automator Quick Action) focus aside, leaving the second-in-line app (the editor) having focus. Unfortunately this didn’t do the trick either. The problem is that this isn’t about visibility. You’re still living in an AppleScript world with that instruction. All this should be able to run in the background, as Launchbar disappears after you select an Action. This is why I’m choosing Ruby to use AppleScripts to bounce around, as the master controller. You know that AppleScript can instruct an application to accomplish something without having it visible or active.
Here is the script and the error:
require 'clipboard'
def osascript(script) = system 'osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten
# mys=<<-TEXT
# tell application "System Events" to keystroke "c" using command down
# TEXT
mys=<<-TEXT
set thisAppName to name of current application
tell application "System Events"
set visible of process thisAppName to false
set the clipboard to the name of first application process whose frontmost is true
end tell
TEXT
osascript(mys)
r = ''
text = Clipboard.paste
text.strip.split("\n").each do |i|
begin
stuff = i.strip.split(/\s*:\s*/)
r += stuff.first.strip.rjust(find_largest_key(text)+5) + " : " + stuff[1].strip + "\n"
rescue
r += i
end
end
Clipboard.copy(r)
mys=<<-TEXT
tell application "System Events" to keystroke "v" using command down
TEXT
osascript(mys)
[format]
RF spacecase (com.viaduct.LaunchBar.action.RFspacecase): Script Error: </Users/rich/.rbenv/shims/ruby /Users/rich/Library/Application Support/LaunchBar/Actions/RF spacecase.lbaction/Contents/Scripts/default.rb>
58:62: execution error: Can’t make selection of application “” into type text. (-1700)
[/format]
I think at this point, I simply need to get that app into the clipboard and reduce the rest of the functionality, to keep this simple.
[format]require ‘clipboard’
def osascript(script) = system ‘osascript’, *script.split(/\n/).map { |line| [‘-e’, line] }.flatten
r = ‘’
mys=<<-TEXT
tell application “System Events” to set the clipboard to name of first application process whose frontmost is true
TEXT
osascript(mys)
origapp = Clipboard.paste
r += “origapp: #{ origapp }\n”
mys = “tell application "#{ origapp }" to set the clipboard to (selection as text)”
r += “mys: #{ mys }\n”
osascript(mys)
Clipboard.copy(r)
mys=<<-TEXT
tell application “BBEdit” to activate
tell application “System Events” to keystroke “v” using command down
TEXT
osascript(mys)[/format]