quoteAppleScriptString returns an AppleScript expression that evaluates to s. Lines are emitted as separate quoted strings joined with `& linefeed &`, because AppleScript double-quoted strings cannot contain literal newlines and there are no \n escape sequences inside the quotes. Tabs are similarly
(s string)
| 206 | // contain literal newlines and there are no \n escape sequences inside |
| 207 | // the quotes. Tabs are similarly handled with `& tab &`. |
| 208 | func quoteAppleScriptString(s string) string { |
| 209 | // Split on newlines; for each line, also split on tabs. |
| 210 | lines := strings.Split(s, "\n") |
| 211 | parts := make([]string, 0, len(lines)) |
| 212 | for i, line := range lines { |
| 213 | // Split each line on tabs, escape pieces, join with `& tab &`. |
| 214 | segs := strings.Split(line, "\t") |
| 215 | quoted := make([]string, len(segs)) |
| 216 | for j, seg := range segs { |
| 217 | quoted[j] = `"` + escapeAppleScriptString(seg) + `"` |
| 218 | } |
| 219 | joined := strings.Join(quoted, " & tab & ") |
| 220 | parts = append(parts, joined) |
| 221 | _ = i |
| 222 | } |
| 223 | return strings.Join(parts, " & linefeed & ") |
| 224 | } |
no test coverage detected