Hello. I'm new to AppleScript and am trying to incorporate it into an Automator script. I'm trying to trim text using a handler I found online. However, using the run handler to set the input variable (the default AppleScript) code for Automator, causes an error saying that I can't have two run commands.
Here's the default script for Automator:
And here's the handler I'm trying to use:
How do I take the input and get it to process using the trimText handler?
Here's the default script for Automator:
Code:
on run {input, parameters}
(* Your script goes here *)
return input
end run
And here's the handler I'm trying to use:
Code:
on trimText(theText, theCharactersToTrim, theTrimDirection)
set theTrimLength to length of theCharactersToTrim
if theTrimDirection is in {"beginning", "both"} then
repeat while theText begins with theCharactersToTrim
try
set theText to characters (theTrimLength + 1) thru -1 of theText as string
on error
-- text contains nothing but trim characters
return ""
end try
end repeat
end if
if theTrimDirection is in {"end", "both"} then
repeat while theText ends with theCharactersToTrim
try
set theText to characters 1 thru -(theTrimLength + 1) of theText as string
on error
-- text contains nothing but trim characters
return ""
end try
end repeat
end if
return theText
end trimText
How do I take the input and get it to process using the trimText handler?