Steven Heller
Steven Heller

Reputation: 11

Automator adding unwanted line breaks

I'm using Automator to create an HTML page and everything works great but I'm running into one small problem. The user is asked for information at the beginning that is then set into variables. The page is created by grabbing some code using Get Specified Text and copying it to the clipboard, getting one of the variables and then putting them both into a text document. This process is then repeated several times, eventually creating an HTML file. I'm running into issues because Automator is creating line breaks (maybe carriage returns?) in between each bit of specified text and each variable. So, what I want to look like this:

<code grabbed using "Get Specified Text" followed by a Variable. And now some more text and another Variable.>

ends up looking like this:

<code grabbed using "Get Specified Text" followed by a
Variable
. And now some more text and another 
Variable
.>

This is breaking my page in a few parts. Is there a way to prevent these line breaks?

Upvotes: 0

Views: 579

Answers (1)

red_menace
red_menace

Reputation: 3422

The items passed along from action to action are in a list, so it appears that setting the TextEdit contents separates the individual items by a newline, which is the normal paragraph delimiter.

Many of the text actions assume TextEdit and/or rich text and don’t use variables (or get along with other plain text actions), so a Run AppleScript action can be used before an action to convert or concatenate items, for example (Mojave):

enter image description here

Automator (or TextEdit for that matter) isn’t really a very good tool for HTML editing. You might take a look at BBEdit (the light version is free), which also has excellent AppleScript support.

EDIT:

Use the following in a Run AppleScript action to combine the text using a specified delimiter (this example uses an empty string):

on run {input, parameters}
  set separator to "" -- text to separate the items with
  set tempTID to AppleScript's text item delimiters
  set AppleScript's text item delimiters to separator
  set output to input as text
  set AppleScript's text item delimiters to tempTID
  return output
end run

Upvotes: 1

Related Questions