Hi folks.
I’m designing a script for Launchbar, which should copy the currently selected text, do something like substitute characters within that text (this is done in Ruby), then paste that text back where the original focus was.
Example 1: Finder file filename is Plugable-ud-ultc4k-triple-4k-display-dock-ports_thumb800-2877640892.jpg and I want to change the dashes to proper spaces.
In this instance, the app is the Finder igself. But I want this script to sniff out what app I’m in, save that in a variable, do the text manipulation (Ruby), then go back to that same app and replace the text. BBEdit is where I live and I often just use these scripts there, but I’d like to extend this to any app. Or hope to do so. I can see some limitations as I have to activate the editing of the filename for the Finder to work. All the same, it saves a lot of frustrating filename edits.
Here is what I have for BBEdit so far, which works on a library of edits:
[format]def osascript(script) = system ‘osascript’, *script.split(/\n/).map { |line| [‘-e’, line] }.flatten
mys=<<-TEXT
tell application “BBEdit” to set the clipboard to (selection as text)
TEXT
osascript(mys)
Clipboard.copy(Clipboard.paste.gsub(‘-’, ’ '))
mys=<<-TEXT
tell application “System Events” to keystroke “v” using command down
TEXT
osascript(mys)[/format]
The issue I have is with the return of the modified text to the original app.
tell application "<original app>" to keystroke "v" using command down
Will that variable work in there?