Alright, I am trying to debug a Text Service in Automator. I have simplified it to this.
- In Automator, create a New Service.
- Make it a text service in any Application.
- Add a Run Applescript Action.
- Populate it with the following:
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:
- Save the service with a name of “blah”.
- Head on over to Text Edit.
- Select some Text.
- Invoke the “blah” Service.
Results: Nothing happens.
Expected: The selected text changes to “blah”.
Not surprisingly, the same results happen changing the Applescript to:
on run {input, parameters}
set input to "blah"
return input
end run
Someone see something, anything wrong with what I have done?
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
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.
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.
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.)
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
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.