Agent Mode

64 views
Skip to first unread message

fold

unread,
Mar 6, 2012, 2:47:06 PM3/6/12
to TextSoap
I'm having trouble getting "Agent Mode" to work in TextSoap 7.

In TextSoap > Preferences I have selected:

Agent Mode: (x) Allow TextSoap to run as agent when externally
accessed

I then quit all aplications and restart my Mac, just to make sure
everything is fresh. But when I run an AppleScript to "externally
access" TextSoap, TextSoap still activates in regular full visibility,
popping to the front with my text in the TextSoap window instead of in
the target application.

If I revert back to TextSoap 6 and use "textsoapAgent" instead of
"textsoap7" the script works fine, TextSoap stays out of the way.

Here are the relevant parts of the scripts:

1. TextSoap 7 - DOES NOT WORK
Even with "Agent Mode" selected in Preferences - TextSoap pops to the
front, fully visible.

property cleaner : "Convert to Uppercase"
tell application "textsoap7" to cleanClipboard with cleaner


2. TextSoap 6 - WORKS
TextSoap stays hidden and out of the way, the script executes
correctly in the target application.

property cleaner : "Convert to Uppercase"
tell application "textsoapAgent" to cleanClipboard with cleaner


Is there some other preference or more that needs to be set to get
this to work in TextSoap 7? Thanks for any tips you can suggest,
looking forward to your reply.

- James Fold
Running on MacBook Air - Mac OS X 10.6.8

Mark Munz

unread,
Mar 6, 2012, 4:22:20 PM3/6/12
to text...@googlegroups.com
To understand why this works differently between TextSoap 6 and 7, a
brief bit of history. With TextSoap 6, there was a separate "agent"
app named, yes, "textsoapAgent." The main application would actually
pass the text to be processed to the v6 agent and then it would get
passed back again. There are a number of limitations with this
approach, especially when working with custom cleaners. This agent was
used by all the various plugins as well - which made sense. The
Scripting Addition was replaced with directly scripting the agent as a
background application, bypassing the main (UI) application.

In TextSoap 7, the text processing code was integrated into the main
application. People did not like the launching effects, so I added an
agent mode which effectively launches TextSoap invisibly and briefly.
This is done by telling the app to launch as an agent. Since TextSoap
Menu and the Automator actions can control the launch of TextSoap,
they're able to signal this option.

The problem comes in with AppleScript and OS X Services, which don't
really allow me to tap into the launching of the app (they launch it
themselves), so they launch it as any standard app. This of course
happens with any scripting app: BBEdit, TextEdit, etc.

There is a near term solution that will work to prevent the app from
becoming visible when invoked with an AppleScript. It basically
requires you to manually launch the app in agent mode before any
"tell" statement directed at the app. Once the app is launched
(invisibly), the tell will simply direct its commands to the invisible
TextSoap.

do shell script "open -b com.unmarked.textsoap7 --args --agent"


tell application "textsoap7" to cleanClipboard with cleaner

It is important to understand that the app only stays around for a few
minutes after its been launched in agent mode (to prevent it from
taking resources for a long time) so you'll need to add that shell
script line before any tell statement to insure it is launched.

Mark

> --
> You received this message because you are subscribed to the Google Groups "TextSoap" group.
> To post to this group, send email to text...@googlegroups.com.
> To unsubscribe from this group, send email to textsoap+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/textsoap?hl=en.
>

--
Mark Munz
unmarked software
http://www.unmarked.com/

fold

unread,
Mar 7, 2012, 2:36:52 AM3/7/12
to TextSoap
Mark, thanks for your thorough explanation and for the history behind
the TextSoap opera.

I removed all the traces of TextSoap 6 and then fresh intalled
TextSoap 7. I rewrote the AppleScript like you suggested, using:

do shell script "open -b com.unmarked.textsoap7 --args --agent"
tell application "textsoap7" to cleanClipboard with cleaner

And it worked!

The first time I ran the script. But if I ran the same script again it
reverted to launching the full visible TextSoap with the jumping up
problem of intercepting the text before it reached the target
application.

I did notice that by watching Activity Monitor, if I waited for the
"invisible version" to expire (or if I quit it manually) before
running the AppleScript the second time, it would work correctly, and
launch invisible. But if I left the invisible version active and then
ran the AppleScript, the full version of TextSoap would run in place
of the invisible version.

Thanks again for your tips, but I think I'll stick with TextSoap 6. It
works fine for my needs, and I actually like the simpler, minimal,
less flashy interface. I'm not sure what I'll miss in 7, I guess the
Regex Lab looks interesting.

I'll keep following your progress. You make a great tool. Good luck.

-Fold

foldand...@gmail.com

unread,
Mar 7, 2012, 2:19:09 PM3/7/12
to text...@googlegroups.com
After looking at this some more, I found a workaround to your workaround:


-- Activate TextSoap in agent mode
tell application "System Events"
if not (exists process "TextSoap") then
do shell script "open -b com.unmarked.textsoap7 --args --agent"
end if
end tell


This solves the problem of TextSoap 7 activating in visible mode if its already active in agent mode for now.

-Fold

Mark Munz

unread,
Mar 7, 2012, 2:47:22 PM3/7/12
to text...@googlegroups.com
Interesting. I've seen different behavior than what you initially
described. But glad to hear there is a better work around for you.
Btw.. what OS are you running under?

I am aware that this remains an issue for certain customers and am
looking at better solutions to the issue long term. Sandboxing has
created some additional complexities to solving this - as I want a
solution that can work for both Mac App Store and direct download
versions.

Mark

> --
> You received this message because you are subscribed to the Google Groups
> "TextSoap" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/textsoap/-/wrG4gQS6KU8J.

foldand...@gmail.com

unread,
Mar 7, 2012, 11:53:17 PM3/7/12
to text...@googlegroups.com, unma...@gmail.com
I'm running Mac OS X 10.6.8 and alternating between TextSoap 7.2 and TextSoap 6.4.2

Thanks for persevering. And yes, although I don't know all the limitations you are up against now, I hear your frustration about not being able to go back to the split app version --- a hidden agent that runs the show --- and a visual front end that creates cleaners. Too bad, that would be nice.

After running it a bit more, I now see very clearly TextSoap 7's two trouble areas that you mentioned:

1. AppleScript

2. OS X Services

These are the two modes I like manipulating text with. And I usually trigger the script or service with a LaunchBar shortcut. So I'll move ahead with going back. And although TextSoap 6 works for me now, I'm wondering about your warning: "TextSoap 6... limitations... especially when working with custom cleaners" but I guess I'll cross that bridge if I come to it.

cheers,
-fold

iota

unread,
May 25, 2012, 9:34:40 AM5/25/12
to text...@googlegroups.com, unma...@gmail.com
Mark,
I can confirm the behavior of the foreground app launching if the agent is called up a second time while running in the background.

Fold,
Thanks for your workaround. It works great.
I tried a different approach by killing the TextSoap agent after the cleaner was done. But that would require me to check if the main application was open or not. In any case your solution is much more elegant!
Reply all
Reply to author
Forward
0 new messages