I am trying to take an Applescript and use it in a much larger ApplescriptObjC project and I have ironed out most differences. Except for one:
The old Applescript gathered some data into a string and append it to a .csv file and It worked! The code was lifted from here: http://macscripter.net/viewtopic.php?id=36861.
In the ApplescriptObjC project in xcode I get this error:
“2015-01-06 04:54:21.729 Tenniskamp[30481:1067784] *** -[AppDelegate doProcess:]: Network file permission error. (error -5000)”
Even if I try to use a non existing file the same error occur.
The essential lines of code looked like this in Applescript:
set filePath to ("Macintosh HD:Users:anders:Desktop:" as text) & "kamp.csv" ”in the top of the file
.
set theResult to writeTo(filePath, theString, text, true) ”just after I have set theString to the info I want to save
.
on writeTo(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as text
set openFile to open for access file targetFile with write permission
if apendData is false then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access file targetFile
end try
return false
end try
end writeTo
With modifications (POSIX file path and a tell current application block) it looks like this in Xcode:
set filePath to "/Users/anders/Desktop/kamp.csv"
.
set theResult to writeTo(filePath, theString, text, true)
.
on writeTo(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
set targetFile to targetFile as text
tell current application
set openFile to open for access file targetFile with write permission
end tell
if apendData is false then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
end writeTo
without the tell current application block I get this warning:
“2015-01-06 05:11:07.658 Tenniskamp[31149:1078147] *** -[AppDelegate doProcess:]: Can’t make current application into type «class fsrf». (error -1700)”
Any suggestions why I get the first error message?
On 10.10 and Xcode 6.1