Hello,
I'm starting my first real ASObjC project and I have run into the well-known problem "cannot make <<class ocid>> into text". I googled a bit and I only managed to find people who used a combobox. There the solution usually was to explicitly coerce the return value to text. In my case, it is a "choose folder" dialog whose return value is the problem. The error message is
Can’t make «class ocid» id «data kptr0000000050AD66638B7F0000» into type text. (error -1700)
The code I used I took from Shane Stanley's book, with some adjustments for my situation. The relevant handler is this:
on showModalSave_(sender) set thePanel to current application's NSOpenPanel's openPanel() tell thePanel setMessage_("Select folder:") setNameFieldStringValue_("Some Name") setShowsHiddenFiles_(false) setTreatsFilePackagesAsDirectories_(false) set theURLString to (POSIX path of (path to desktop)) tell current application's NSURL to set myURL to fileURLWithPath_isDirectory_(theURLString, true) setDirectoryURL_(myURL) setCanChooseFiles_(false) setCanChooseDirectories_(true) setAllowsMultipleSelection_(false) set returnCode to runModal() end tell set returnCode to returnCode as integer if returnCode = (current application's NSFileHandlingPanelOKButton) as integer then log "1" set theURLs to thePanel's URLs() as list log "2" set thePosixPath to item 1 of theURLs log "3" -- and if you want an HFS path: set my theHFSFolder to (((thePosixPath as text) as POSIX file) as text) set my theFolder to thePosixPath log theFolder else log "Cancel pressed" end if
Logging up to number "3" works, so the next line must be the offending one. OK, so I have two questions: 1. What do I do wrong? 2. What IS class ocid? I know many programming languages and environments, and in every single one so far the important thing to know was what things really were.
The documentation about the return value of NSOpenPanel gives me
NSURL* theDoc = [[panel URLs] objectAtIndex:0]; |
So it seems I have a pointer to an object of Class NSURL in my variable thePosixPath. Is there any documentation how to get from those pesky pointers to the stuff pointed to? I am more interested in an explanation of things in general rather than a fix for this one situation.
(Background info: I want the path to the folder selected and then tell an application to open every file in it, do some manipulation to it, save and close. I could do it without ASObjC but if I did that it would be one of the "death by dialog" scripts since there are numerous settings to be made.)
Thanks in advance, Marion Dickten |