OmegaT and Snow Leopard and Services !

0 views
Skip to first unread message

JC Helary

unread,
Sep 19, 2009, 8:35:42 AM9/19/09
to Mac for Translators
Snow Leopard comes with a few interesting features as well as a few
annoyances, like Java 6 that does not play along too well with OmegaT:
buggy anti-aliasing, slowness etc, all "features" that we don't really
need.

But there is at least one thing that we really will learn to like
about Snow Leopard, it is the ability for Automator to create
Services...

Remember my last attempt at that ? I was trying to create a script to
extract tags from OmegaT segments for later pasting in the target field.

The only solution I came up with was to 1) trigger the Applescript
menu display, 2) make it a way that it was on the leftmost side of the
menu icons, 3) call it with an accessibility shortcut 4) cycle through
the scripts with the arrow buttons to call the Applescript I wanted.

And the Applescript itself was only here to allow me to access the
process from the UI. The idea being that what I really wanted was a
shell script (only a sed command in fact) called with a keyboard
shortcut.

Well, Snow Leopard is bringing us that, kind of :)

Launch Automator, select "service" as your next chef-d'œuvre, insert a
"run shell script command", put your sed code there.

Then, select "no input" for what the Service gets, and save.

Now, the Services menu should have a "General" menu with your service
listed there.

Go to System Preferences > Keyboard > Services and assign a keyboard
shortcut to your service. Choose one that is not already taken by
OmegaT.

Et voilà ! Now you have general keyboard access to your script.

Try this in the "run shell script" action:
=================
sed 's/^[^<]*//;s/[^>]*$//;s/>[^<]*</></g' ~/Library/Preferences/
OmegaT/script/source.txt | tr -d '[

]' | pbcopy
=================

Assign it a keyboard shortcut, and now, enter a segment with tags.
Call the script, then Cmd+V to paste in Target.

You're supposed to have all the tags of the source segment pasted in
Target.

Et voilà ! No need to fiddle with the Applescript menu !


Now, this is for extracting the source, without the tags:
=================
export __CF_USER_TEXT_ENCODING=0x1F5:0x8000100:0x8000100
sed 's/<[^>]*>/ /g' ~/Library/Preferences/OmegaT/script/source.txt |
pbcopy
=================

The first line is here so that pbcopy uses UTF-8 by default. It should
be in your .profile file, but having only it here won't hurt (see http://www.macosxhints.com/article.php?story=20081231012753422
for the hint).


And this is for extracting the text in the selection, for this one, we
won't use OmegaT's ability to output the selection to ~/Library/
Preferences/OmegaT/script/selection.txt, we'll use Automator's ability
to use the selection as input to the shell by selecting "Service
receives text" :
=================
export __CF_USER_TEXT_ENCODING=0x1F5:0x8000100:0x8000100
sed 's/<[^>]*>/ /g' | pbcopy
=================

I've been testing the new services above on a test project and I can
tell it is much faster in 2 ways: first, not need for circumvolutions
to access the command itself, only one shortcut is enough. Second, it
looks like running the services directly as shell scripts and not as
shell scripts run from an Applescript is much faster.

In any case, you now have 3 new functions for OmegaT on the Mac (Snow
Leopard) !

Jean-Christophe Helary (JA/EN > FR)

------------------------------------
http://mac4translators.blogspot.com/
http://twitter.com/brandelune

Reply all
Reply to author
Forward
0 new messages