Read and Write Errors

after a while I opened my app again and got same errors now. There are obviously read und write errors. Maybe it’s an old topic meanwhile, but be patient with me.

property NSMutableArray : class "NSMutableArray"

property userLocationSchuelerDaten : (path to "asup" from user domain) & "SchuelerListenDaten" as text

” reading:
set myPath to POSIX path of ((userLocationSchuelerDaten as string) & ":" & (selectedContent as string))
display alert (myPath) ” - OK
set myDataSource to NSMutableArray's alloc()'s initWithContentsOfFile: myPath 

display alert (myDataSource)”> "msng"

on error number: -1708 ("doesn't understand message")

” writing:

set FILE_PATH to POSIX path of ((userLocationSchuelerDaten as string) & ":" & (kursname as string))

if not ((nDataSource's writeToFile:FILE_PATH atomically:1) as boolean) then 


Many thanks in advance!


What are you trying to achieve?
What is the error?
What version of OSX are you using?

What happens if you run the following?

set deskPath to POSIX path of (path to desktop)

set deskPath to current application's NSString's stringWithString:deskPath
set FILE_PATH to deskPath's stringByAppendingPathComponent:"Test file"
set nDataSource to current application's NSMutableArray's arrayWithArray:{1, 2, 3, 4, 5}
set theResult to (nDataSource's writeToFile:FILE_PATH atomically:true) as boolean
if not theResult then
	display dialog "Saving failed"
	error number -128
end if
set myDataSource to (NSArray's arrayWithContentsOfFile:FILE_PATH)'s mutableCopy()
set theList to myDataSource's componentsJoinedByString:", "
display dialog (theList as text)

Is one the objects in the array maybe an non property list object (or create subclasses of it)? What is the structure of the plist file? Does it start with the code below?

edit: Can’t I use XML tags [format]?

The first part works properly:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

The second (reading) part did nothing: no answer, no crash.

My saved file has the form of a dict:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
		<string>Albrecht, Katrin</string>
		<string>Burger, Klaus</string>

“derName” (theName) wil be inserted into a table view by the key in the course of the run.


No it has the form of an array containing dictionaries. When I store the following contents in a file named “test.plist” on my desktop:

I can succesfuly use the following code:

use framework "Foundation"
use scripting additions

set theFile to POSIX path of ((path to desktop as string) & "test.plist")
set nDataSource to current application's NSArray's alloc()'s initWithContentsOfFile:theFile
return nDataSource as list

The code will return as expected:

Can you confirm that this is the same on your machine?

My apologies – I left out current application’s:

set myDataSource to (current application's NSArray's arrayWithContentsOfFile:FILE_PATH)'s mutableCopy()

Where are the files coming from? Is it possible they are binary property list files? In that case they need to be handled differently.

To DJ Bazzie Wazzie:

Sorry, but my app is perhaps to old. It doesn’t understand

use framework “Foundation”
use scripting additions

and without it, it works not either.

To Shane:

Now your snippet are working correctly. I’ll try to adopt it into my app and give a response later.

The saving lines and the ‘form’ of saving are on top (but I think I haven’t understand the problem).


I think DJ was assuming a standard script – but I presume this is an Xcode project.

To make a notice beforehand: my app worked up to now.
But now I can read and write the file from and to everywhere but not to (my)Library/Application Support/“myFile” .
The name of “myFile” is readable but the contents of it is not loadable.
What happened meanwhile?


How are you getting the path to the Application Support folder?

That sounds awfully like you might accidentally be trying to save in the wrong Application Support folder.

That’s my script:

property userLocationSchuelerDaten : (path to "asup" from user domain) & "SchuelerListenDaten" as text

set myPath to POSIX path of ((userLocationSchuelerDaten as text) & ":" & (selectedContent as text))

” - selectedContent: user selected a file in a tab. view

display alert (myPath as text) ”>

/Festplatte/Users/heinrichhoffmann/Library/Application Support/SchuelerListenDaten/Testliste kurz  ”> correct

( /Harddisk/Users/myComputer/Library/App..Sup/myFolder/myFile)

set helpDataSource to NSMutableArray's alloc()'s initWithContentsOfFile:myPath

set anzahl to helpDataSource's |count|()
display alert (anzahl) ”> correct

set a to (helpDataSource's valueForKey:"derName") as list ”(see the pList above)

display alert ("a")  ”> error -1708              				
display alert (a) ”> error -1700

I think you should be using:

display dialog (a as text)

However, try inserting this line and see what appears in the Console:

current application's NSLog("helpDataSource = %@", helpDataSource)

Meanwhile I noticed that Apple has published a new Xcode version (Xcode 8) without an automatic update. My OS system is OS 10.12 now.
The maximum of project target of my Xcode version is to set for 10.11.
Does that be the reason for my troubles now?

I don’t get any more debug informations in the pane below, so not
current application’s NSLog(“helpDataSource = %@”, helpDataSource).

Compiling the file in the project setting view I get in the debugging view pane by clicking the ˜Debug View Hierarchy’ button the following message:

warning: could not load any Objective-C class information from the dyld shared cache. This will significantly reduce the quality of type information available.

You shouldn’t run earlier than Xcode 8 under 10.12.

Feel free to email me with the project…

if the situations allows you too. Running Xcode 3.2 to develop for 10.12 here in some occasions.

Let me rephrase that. Apple’s recommendation is that if you’re running 10.12, you should be running Xcode 8.x.