• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
ASObjC Beginners Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ASObjC Beginners Problem


  • Subject: ASObjC Beginners Problem
  • From: Marion Dickten <email@hidden>
  • Date: Wed, 10 Apr 2013 10:15:34 +0200

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
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: ASObjC Beginners Problem
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: New to Applescript
  • Next by Date: ASObjC: current application
  • Previous by thread: Re: New to Applescript
  • Next by thread: Re: ASObjC Beginners Problem
  • Index(es):
    • Date
    • Thread