Replace folders with wrappers, without rewriting too much code?

It’s not a matter of “wouldn’t want” but “can’t” , and like Bernard stated somewhere recently, I don’t like writing code that I don’t understand. I can try to follow the example in the docs (or yours? or leonsimard’s?), but I still won’t know what I’m doing. If this is the way Apple wants us to go, it would be useful if they would provide an explanation of how to do it, rather than a single example.

Ric

Oh, I agree it’s not well documented. But I think the form in Xcode 4 makes things a bit clearer. For an Xcode 3 project, I fired up Xcode 4, made a dummy app, filled in the form, then copied and pasted from one Info.plist display to the other – the copy went fine, even between versions of Xcode.

But you’re right: it shouldn’t ought to be this hard…

Well, at this point I only have XCode 3. Is it ok to have both versions present at the same time? It sounds like xcode 4 still has some problems, and I’m not ready to abandon the tried and true just yet.

Ric

I’m sticking with Xcode 3 as long as I can. But you can have both installed – you just set the destination when you install so it doesn’t overwrite version 3. I have a separate folder called Xcode4 at root level, and they both coexist fine.

But that’s a lot of effort to go to for just UTI exports. Control-click on your project’s Info.plist file and choose Open as text. Paste in the XML from the docs. Then control-click and choose Open as XML Property List. Now the stuff will be in an easily editable form.

Thanks for the tip, I’ll try it that way rather than downloading XCode 4

Ric

Finally I have downloaded again XCode 3.2 (4.73 Gb, just a breeze.) and opened my project inside it, checked the “package” box for my document, and opened it again in XCode 4.

That’s the XCode 4 version:

  1. Click on “Target” to bring it to the Editor
  2. Add a new document type, give any description name, Class none, Extension to your wrapper type, Role as Editor.
    3. Click on the disclosure triangle for Additional document type properties and add this key:

LSTypeIsPackage / type boolean / YES

You see, finally I was wrong in my first post: it IS really “Set the wrapper bit of the folder to true”. :lol:

Maybe I’m too stupid to understand, but I can’t get thinks work.

I finally got to create a wrapper, but I can’t use it like a regular folder.

I want to do the equivalent of:

That is really simple to do in Applescript, and maybe I should let this as it. But I am as stubborn as stupid :mad:, and I want to store my .atxt files into a wrapper.

Could you help me? I’m stuck for days and my program does not progress in other areas.

Thanks,

It would be more helpful if you posted the code that didn’t work.

What do you get when you cal fileWrappers() on your wrapper?

script WrapAppDelegate
    property parent : class "NSObject"
    property NSDictionary : class "NSDictionary"
    property aWrapper : missing value
    property manager : missing value
    property gWindow : missing value
    property gWindowTitle : missing value
    property gWrapperPath : missing value
    property gWrapperURL : missing value

    on applicationWillFinishLaunching_(aNotification)
        set manager to current application's NSFileManager's defaultManager()
    end
	
    on createWrapper_(sender)
        set sp to current application's NSSavePanel's savePanel()
        sp's setAllowedFileTypes_({"adwr"})
        sp's setNameFieldStringValue_("Untitled")
        sp's setExtensionHidden_(1)
        sp's runModal()
        set gWrapperURL to sp's |URL|()
        set aWrapper to current application's NSFileWrapper's alloc()'s initDirectoryWithFileWrappers_(missing value)
        aWrapper's writeToURL_options_originalContentsURL_error_(gWrapperURL, current application's NSFileWrapperWritingAtomic, missing value, missing value)
        set my gWrapperPath to |path| of gWrapperURL as text
        manager's changeCurrentDirectoryPath_(gWrapperPath)
        gWindow's setTitleWithRepresentedFilename_(gWrapperPath)
    end

    on openWrapper_(sender)
        set sp to current application's NSOpenPanel's openPanel()
        sp's setAllowedFileTypes_({"adwr"})
        sp's setNameFieldStringValue_("Untitled")
        sp's setExtensionHidden_(1)
        sp's runModal()
        set gWrapperURL to sp's |URL|()
        set my gWrapperPath to |path| of gWrapperURL as text
        gWindow's setTitleWithRepresentedFilename_(gWrapperPath)
    end
    
    on createFileInside_(sender)
        tell application "Finder" to open gWrapperPath
        tell application "Finder" to make new file with properties {name:"test.adoc", creator type:"WRAP"}
    end

end

Create and open work well: the wrapper is created, the icon is correct, and I get no error.

But createFileInside the wrapper “Test.adwr” gives error:

Your problem is a basic scripting one: the Finder wants file references or aliases, not just paths.

Your problem is a basic scripting one

What a relief! Ok, we have URLs, paths, POSIX files, files, and aliases (and maybe an inode number also.) And I thought I was a complicated man. :confused:

Could you remember me how I tell my old friend the Finder to open this wrapper? So far I used “choose folder” and got the returned parameter to open the folder – and not the NSOpenPanel.

Thank you!

Edit : it’s OK, I found my answers in an older post (2011-03-26) from rdelmar. For the moment I can progress.

Just add “as alias”, should work then.

Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)

Nope.

My next goal is to avoid all the tell application “Finder” to. and replace them by Cocoa calls

Thanks anyway!

Oh, then NSFileManager is your man. Has tons of methods that can probably do everything you need. Cheers!

Browser: Safari 6533.18.5
Operating System: Mac OS X (10.6)

No offense, your project seems to be quite complex.
I recommend to spend a few months to learn the language (Objective-C, not this hybrid ASOC). Believe me, It’s worth it

Don’t tempt me, Stefan :wink:

I know there is a leap between Applescript, and even ASOC, and Objective-C. For me it’s the same difference as between snorkeling and diving: by using ASOC, I see the depths of Cocoa but I stay just under the surface. and I breath through a |pipe|.

But I let me some time: for ten years I didn’t program anything, so ASOC is a very good opportunity to make “serious” programming again. Don’t get me wrong: Applescript is a very good high-level language (not object-oriented, but a real object language). But I’m not interested in piloting the programs of other programmers: I’d like to program, too. For an amateur like me, ASOC is a good way to to meet old friends again: the file, the window managers of the ToolBox. They may have change, but after all a Mac remains a Mac. :slight_smile:

Anyway, when I’ll decide to dive for good, I’ll stay at MacScripters because I didn’t find such a kindness and efficiency anywhere else.

Regards,

I don’t know what all the fuss is about here – you already have your wrapper’s URL, all you need to do is append the name of your file to it, just like you would for any directory, and save your file. Let’s say you have an array called theArray that you want to save inside your wrapper, just do this:

set wholeURL to current application's NSURL's URLWithString_relativeToURL_("test.adoc", gWrapperURL)
		theArray's writeToURL_atomically_(wholeURL, 1)

Ric

Ric,

Thank you for your post. You gave me another way to do this two months ago, I retrieved it yesterday:

Both methods work perfectly, I think this one avoids creating new NSURL objects at each wrapper access (if the app works in one directory at a time; if not, your last method is certainly better).

About your remark, and as StefanK said, I suppose it is no offense to mention the NSFileManager in a topic about file operations. But you’re certainly right, this is a little offtopic.

I’ll be back. :cool: