Parsing a set of lines in Applescript

Parsing a set of lines in Applescript

灵芸 发布于 2021-11-28 字数 529 浏览 945 回复 1 原文

I am trying to parse a set of lines read from a file in Applescript.

This is how my code looks:

my status_dialog(indexData)
set AppleScript's text item delimiters to return
set indexFreq to (text items 1 thru 1 of indexData)

indexData contains a set of lines.
The line delimiter is not working. indexFreq returns me the whole set of lines again instead of the first one.

I am a newbie in here and the online resources arent helping me in this.

Many thanks!
Pradeep

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。

扫码加入群聊

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过去的过去 2022-06-07 1 楼

Your code should work as expected. The problem may be that return is not the correct character for this particular set of lines. Line breaks can be carriage return, line feed or both, depending on the program or system that created the file.

You can try using different characters instead of return:

tell me to set the text item delimiters to (ASCII character 10) --// LF
tell me to set the text item delimiters to (ASCII character 13) --// CR

Also, to make sure the rest of your code is set up proprly, do a simple test:

set test_string to "thisQisQaQtest"
set the text item delimiters to "Q"
return text items of test_string

This should produce the following (in your AppleScript console):

{ "this", "is", "a", "test" }