Wednesday, July 18, 2018

#1 2013-03-15 01:01:16 pm

Stephen Magladry
Member
Registered: 2009-02-04
Posts: 23

problem with text service actually working

Alright, I am trying to debug a Text Service in Automator. I have simplified it to this.

1. In Automator, create a New Service.
2. Make it a text service in any Application.
3. Add a Run Applescript Action.
4. Populate it with the following:

Applescript:


on run {input, parameters}
   set newString to "blah"
   return newString
end run

Running this from within Automator generates the usual warning, then runs and show a result of "blah", as expected.


I then:
1. Save the service with a name of "blah".
2. Head on over to Text Edit.
3. Select some Text.
4. Invoke the "blah" Service.

Results: Nothing happens.
Expected: The selected text changes to "blah".

Not surprisingly, the same results happen changing the Applescript to:

Applescript:


on run {input, parameters}
   set input to "blah"
   return input
end run

Someone see something, anything wrong with what I have done?


Filed under: Automator, Text Service

Offline

 

#2 2013-03-15 01:23:24 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: problem with text service actually working

Hello.

This works for me, when I check off "replaces selected text", on top of the service, where you choose what the service should do.

I am running Snow Leopard


Filed under: Text Service

Offline

 

#3 2013-03-15 01:27:16 pm

Stephen Magladry
Member
Registered: 2009-02-04
Posts: 23

Re: problem with text service actually working

Damn! I hate it when the solution is so simple! lol What a waste on time on my part!

Thanks for steering me straight, McUsrII.

Offline

 

#4 2013-03-15 01:33:16 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: problem with text service actually working

Now…

The most important thing is trying, the second is not giving up.

Things like that happens to most of us from time to time. wink

Happy Scripting.

By the way, Auomator services are hard to debug Applescripts in,

This handler makes it easier, the second parameter is like "ThisService" which becomes a file "ThisService.Log" in ~/Library/Logs (YourHomeFolder:Library:logs:ThisService.log). When you double click that file, it will open up in Console app, and from then onwards, you can watch what happens in your service. call it with "my logit(param1,param2)".

(Test it in a regular Applescript first, so you see how it works.)

Applescript:

to logit(log_string, log_file)
   do shell script ¬
       "echo `date '+%Y-%m-%d %T: '`\"" & log_string & ¬
       "\" >> $HOME/Library/Logs/" & log_file & ".log"
end logit

Last edited by McUsrII (2013-03-15 01:34:20 pm)


Filed under: log

Offline

 

#5 2013-03-15 01:41:21 pm

Stephen Magladry
Member
Registered: 2009-02-04
Posts: 23

Re: problem with text service actually working

Thanks for the input. Obviously, my script I actually did use turned out to be more in depth than what I posted here.

I debug in AppleScript Debugger: Great product BTW.

I made an on Runner with the same parameters as on run. I then called Runner with the parameters I wanted to use.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)