2013-05-31 70 views
1

我有一個數字寫在一個文本文件。是否可以在文本文件中添加另一個號碼,然後用新號碼替換舊號碼?我的繼承人代碼:添加一個數字到變量applescript

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 

回答

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 
+0

這正是我想要做的,它的工作完美。謝謝! –

+0

不客氣。不過,我很好奇,你用腳本來綁定什麼? – mcgrailm

+0

@mcgralim我以前使用過腳本來製作一個計算器。 '將theMath設置爲返回的文本(顯示對話框「在這裏插入數學問題」默認答案「」buttons {「Cancel」,「Ok」}}默認按鈕2)' 運行腳本theMath –

相關問題