Sunday, March 26, 2017

#1 2016-10-24 02:11:39 pm

Heiner
Member
From: Germany
Registered: 2007-08-25
Posts: 147

Read and Write Errors

Hello,
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.

Applescript:


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

error

Many thanks in advance!

Heiner

Offline

 

#2 2016-10-24 03:05:02 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: Read and Write Errors

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

Offline

 

#3 2016-10-24 06:20:01 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Read and Write Errors

What happens if you run the following?

Applescript:

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)


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#4 2016-10-25 01:37:45 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: Read and Write Errors

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?

<plist version="1.0">
<array>

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

Last edited by DJ Bazzie Wazzie (2016-10-25 01:40:46 am)

Offline

 

#5 2016-10-25 04:27:17 am

Heiner
Member
From: Germany
Registered: 2007-08-25
Posts: 147

Re: Read and Write Errors

The first part works properly:

Applescript:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
   <integer>1</integer>
   <integer>2</integer>
   <integer>3</integer>
   <integer>4</integer>
   <integer>5</integer>
</array>
</plist>

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

My saved file has the form of a dict:

Applescript:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
   <dict>
       <key>derName</key>
       <string>Albrecht, Katrin</string>
   </dict>
   <dict>
       <key>derName</key>
       <string>Burger, Klaus</string>
   </dict>

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

Heiner

Offline

 

#6 2016-10-25 05:38:03 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: Read and Write Errors

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:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
   <dict>
       <key>derName</key>
       <string>Albrecht, Katrin</string>
   </dict>
   <dict>
       <key>derName</key>
       <string>Burger, Klaus</string>
   </dict>
</array>
</plist>

I can succesfuly use the following code:

Applescript:

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:

{{derName:"Albrecht, Katrin"}, {derName:"Burger, Klaus"}}

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

Offline

 

#7 2016-10-25 05:50:55 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Read and Write Errors

Heiner wrote:

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

My apologies -- I left out current application's:

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#8 2016-10-25 05:52:55 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Read and Write Errors

Heiner wrote:

My saved file has the form of...

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#9 2016-10-25 06:27:22 am

Heiner
Member
From: Germany
Registered: 2007-08-25
Posts: 147

Re: Read and Write Errors

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).


Heiner

Offline

 

#10 2016-10-25 06:50:26 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Read and Write Errors

Heiner wrote:

To DJ Bazzie Wazzie:

Sorry, but my app is perhaps to old.

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#11 2016-11-01 11:32:21 am

Heiner
Member
From: Germany
Registered: 2007-08-25
Posts: 147

Re: Read and Write Errors

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?

Heiner

Offline

 

#12 2016-11-01 05:44:17 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Read and Write Errors

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#13 2016-11-02 08:56:40 am

Heiner
Member
From: Germany
Registered: 2007-08-25
Posts: 147

Re: Read and Write Errors

That's my script:

Applescript:


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

Offline

 

#14 2016-11-02 06:06:36 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Read and Write Errors

I think you should be using:

Applescript:

display dialog (a as text)

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

Applescript:

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#15 2016-11-03 06:48:17 am

Heiner
Member
From: Germany
Registered: 2007-08-25
Posts: 147

Re: Read and Write Errors

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.
(lldb)

Offline

 

#16 2016-11-03 06:52:24 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Read and Write Errors

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

Feel free to email me with the project...


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#17 2016-11-03 07:17:18 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2590

Re: Read and Write Errors

Shane Stanley wrote:

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

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

Offline

 

#18 2016-11-03 07:22:35 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 4963

Re: Read and Write Errors

DJ Bazzie Wazzie wrote:

if the situations allows you too.

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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.207 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)