AppleScript初学者:突然它赢了';不要创建文本文件
不再创建文本文件。我该怎么做才能使这个函数工作呢。没有错误。下面的AppleScript代码是一个基本模板,演示如何创建文本文件,然后写入其中AppleScript初学者:突然它赢了';不要创建文本文件,applescript,Applescript,不再创建文本文件。我该怎么做才能使这个函数工作呢。没有错误。下面的AppleScript代码是一个基本模板,演示如何创建文本文件,然后写入其中 set textFile to "/Users/whomever/Desktop/TEXT.txt" 但是,如果您更喜欢使用更少代码的不同选项,下面的AppleScript代码将获得相同的结果 property textFile : (path to desktop as text) & "TEXT.txt&quo
set textFile to "/Users/whomever/Desktop/TEXT.txt"
但是,如果您更喜欢使用更少代码的不同选项,下面的AppleScript代码将获得相同的结果
property textFile : (path to desktop as text) & "TEXT.txt"
set randomText to "Blah Blah Blah"
writeToSomeFile(textFile, randomText) -- Will Create File "TEXT.txt" If Not Exists
-- Additional Code Here
-- More Code Here
tell application "Finder"
activate
reveal textFile
end tell
----- Place Handler Definitions Beneath This Line At Bottom Of Script -----
on writeToSomeFile(pathToFileToWriteTo, someText)
try
set writeToFile to open for access pathToFileToWriteTo with write permission
write someText & linefeed to writeToFile as text starting at eof
close access writeToFile
on error errMsg number errNum
close access alias pathToFileToWriteTo
end try
end writeToSomeFile
您的语句只是声明一个变量,并用文本值初始化它。在我的脑子里,你可以做
doshell脚本“touch”
来创建一个新文件。现在,我的AppleScript行为怪异,没有向文件中写入文本。我使用了你的建议,它至少创建了.txt文件,所以感谢你提供的信息,但我仍然无法以我知道的方式将数组写入文本文件。是的,我知道你问这个问题是你试图在另一个线程中解决的更大问题的一部分。我们可以在那里继续讨论,以保持讨论的组织性。
property textFile : (path to desktop as text) & "TEXT.txt"
set randomText to "Blah Blah Blah"
(* If textFile Does Not Exist Yet, This Will Create The File And Write
randomText To It. Otherwise it will append randomText to the file *)
do shell script "echo " & quoted form of randomText & " >> " & ¬
quoted form of POSIX path of textFile