You are not logged in.
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
What are you trying to achieve?
What is the error?
What version of OSX are you using?
Offline
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/
latenightsw.com
Offline
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 12:40:46 am)
Offline
The first part works properly:
Applescript:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "[url]http://www.apple.com/DTDs/PropertyList-1.0.dtd[/url]">
<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" "[url]http://www.apple.com/DTDs/PropertyList-1.0.dtd[/url]">
<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
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
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/
latenightsw.com
Offline
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/
latenightsw.com
Offline
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
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/
latenightsw.com
Offline
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
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/
latenightsw.com
Offline
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
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/
latenightsw.com
Offline
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
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/
latenightsw.com
Offline
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
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/
latenightsw.com
Offline