在变量applescript中添加一个数字

时间:2013-05-31 00:25:45

标签: variables text numbers applescript add

我有一个用文本文件写的数字。是否可以在文本文件中添加另一个数字,然后用新数字替换旧数字?继承我的代码:

set theFile to POSIX path of "Users:Tyler:Documents:File.txt"
open for access theFile
set theFileContents to read theFile

set theNewFile to run script theFileContents + 1
tell application "TextEdit"
set eof of theFileContents to 0
write theNewFile to theFileContents

1 个答案:

答案 0 :(得分:0)

如果我正确理解你的问题你只想要一个带有字符串的文本文件并将该字符串转换为数字然后将该数字的值增加1将其作为字符串写回文件并保存它完成繁荣对 ?如果这就是你的意思,请告诉我。

set docsFolder to path to documents folder

set afile to "" & docsFolder & "File.txt"
open for access file afile with write permission
set oldNum to read file afile
set newString to ((oldNum as number) + 1) as string
set eof file afile to 0
log newString
write newString to file afile starting at eof

close access file afile