无法弄清楚如何将 AppleScript 的结果打印到文本文件中

无法弄清楚如何将 AppleScript 的结果打印到文本文件中

下面的代码有效。它在脚本编辑器的结果选项卡中返回列表变量。我想将其写入文本文件。

set A to text
set B to text
set C to text
set D to text
set E to text
set F to text
set G to text
set H to text
set I to text
set J to text
set K to text
set L to text
set M to text
set N to text
set O to text
set P to text
set Q to text
set R to text
set S to text
set T to text
set U to text
set V to text
set W to text
set X to text
set Y to text
set Z to text
set Alphabet1 to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set Alphabet2 to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
set Alphabet3 to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}

set IdleLoop2 to "set value of cell (µ∑†∏µ & LastRowCrypto + 1) to current¥Price"

set findText3 to "∑"
set findText4 to "†"
set findText5 to "∏"
set findText6 to "¥"
set ListOfExcel to {}
repeat with A from 1 to length of Alphabet1
    set replaceText4 to item A of Alphabet1
    set newText4 to do shell script "sed 's|" & quoted form of findText3 & ¬
        "|" & quoted form of replaceText4 & "|g' <<< " & quoted form of IdleLoop2
    copy newText4 to the end of ListOfExcel
end repeat

repeat with B from 1 to length of Alphabet2
    repeat with D from 1 to 26
        set IdleLoop3 to item D of ListOfExcel
        set replaceText5 to item B of Alphabet2
        set newText5 to do shell script "sed 's|" & quoted form of findText4 & ¬
            "|" & quoted form of replaceText5 & "|g' <<< " & quoted form of IdleLoop3
        copy newText5 to the end of ListOfExcel
    end repeat
end repeat
repeat with C from 1 to length of Alphabet3
    repeat with E from 27 to 53
        set IdleLoop4 to item E of ListOfExcel
        set replaceText6 to item B of Alphabet3
        set newText6 to do shell script "sed 's|" & quoted form of findText5 & ¬
            "|" & quoted form of replaceText6 & "|g' <<< " & quoted form of IdleLoop4
        copy newText6 to the end of ListOfExcel
    end repeat
end repeat

return ListOfExcel

我尝试过这个:

set the logFile to ((path to desktop) as text) & "DOG.txt"
set the logText to ListOfExcel
try
    open for access file the logFile with write permission
    write (logText & return) to file the logFile starting at eof
    close access file the logFile
on error
    try
        close access file the logFile
    end try
end try

并尝试了这个:

do shell script "echo " (I forgot the rest)

并尝试了这个:

write ListOfExcel to textFile

但这些想法似乎行不通。

我只是不明白改变列表变量格式所必需的东西,如何以权限调用文本文件并让 AppleScript 写入该文件。

答案1

在回顾了工作内容后脚本在你的原帖中内容为了ListOfExcel 列表,我不确定你为什么要把它写给文件但是,假设你想写内容ListOfExcel 列表文件作为文本return ListOfExcel,然后在工作中更换代码在你的 OP 中显示以下内容例子 苹果脚本 代码,即使用变量如你的 OP 所示:

set the logFile to ((path to desktop) as text) & "DOG.txt"

set {TID, AppleScript's text item delimiters} to ¬
    {AppleScript's text item delimiters, linefeed}
set logText to ListOfExcel as text
set text item delimiters to TID

writeToFile(logText, logFile, true)

on writeToFile(theData, theFile, overwriteExistingContent)
    try
        set theFile to theFile as string
        if theFile contains "/" then
            set theOpenedFile to open for access theFile with write permission
        else
            set theOpenedFile to open for access file theFile with write permission
        end if
        if overwriteExistingContent is true then set eof of theOpenedFile to 0
        write theData to theOpenedFile starting at eof
        close access theOpenedFile
        return true
    on error
        try
            close access file theFile
        end try
        return false
    end try
end writeToFile

笔记

writeToFile(theText, theFile, overwriteExistingContent) 处理程序稍微修改了一下处理程序从:读写文件

处理程序来自链接的苹果修改了支持文档以同时处理POSIX高频振动+ 文件路径,以及它的姓名也改变了。


注意:例子 苹果脚本 代码就是这样,没有任何包括错误处理不包含任何额外的错误处理视情况而定。用户有责任添加任何错误处理视情况而定,需要或想要。请查看尝试 陈述错误 陈述在里面AppleScript 语言指南。 也可以看看,处理错误。此外,使用延迟 命令delay 0.5在适当的情况下,可能需要在事件之间进行价值延迟设置得当。

相关内容