Variables 如何将数字变量保存到applescript中的文件?
我正在尝试创建一个简单的计数器,每次运行脚本时,它都会向计数中添加一个计数器。我尝试过使用某个属性,但没有效果,因为每当编辑脚本或关闭计算机时,该属性都会重置。这是我从中获取的代码 有了这个,我得到了一个错误: 无法将“:Users:hardware:Library:Scripts:Applications:LightSpeed:CurrentProductCode.txt”转换为类型文件 如果我在第一个“打开以访问文件”之后添加“将文件设置为文件别名”,则代码中的内容会进一步,但会出现另一个错误: 无法将“1776”转换为整数类型Variables 如何将数字变量保存到applescript中的文件?,variables,applescript,read-write,Variables,Applescript,Read Write,我正在尝试创建一个简单的计数器,每次运行脚本时,它都会向计数中添加一个计数器。我尝试过使用某个属性,但没有效果,因为每当编辑脚本或关闭计算机时,该属性都会重置。这是我从中获取的代码 有了这个,我得到了一个错误: 无法将“:Users:hardware:Library:Scripts:Applications:LightSpeed:CurrentProductCode.txt”转换为类型文件 如果我在第一个“打开以访问文件”之后添加“将文件设置为文件别名”,则代码中的内容会进一步,但会出现另一个错
现在我没有主意了。我用谷歌搜索了整个地方,没有找到任何适合我的。谢谢我喜欢使用脚本对象来存储数据:
set thePath to (path to desktop as text) & "myData.scpt"
script theData
property Counter : missing value
end script
try
set theData to load script file thePath
on error
-- On first run, set the initial value of the variable
set theData's Counter to 0
end try
--Increment the variable by 1
set theData's Counter to (theData's Counter) + 1
-- save your changes
store script theData in file thePath replacing yes
return theData's Counter
令人惊叹的!谢谢工作完美。我知道必须有更好的方法来存储数值变量!再次感谢
set thePath to (path to desktop as text) & "myData.scpt"
script theData
property Counter : missing value
end script
try
set theData to load script file thePath
on error
-- On first run, set the initial value of the variable
set theData's Counter to 0
end try
--Increment the variable by 1
set theData's Counter to (theData's Counter) + 1
-- save your changes
store script theData in file thePath replacing yes
return theData's Counter