How to know if a folder is a Package or not ?

[h]How to know if a folder is a Package or not ?[/h]

I use an AppleScript command but it’s very long.

set ThisItemPackage to (package folder of item1PosIX)

item1PosIX is the Path of my folder, and it return a Boolean value (in ThisItemPackage).

Thanks.

There is such a function in the MacOSLib package.

http://github.com/macoslib/macoslib

Or isBundleMBS function on folderitem class if you have our MBS plugins.

I downloaded MacOSLib package but it’s longest than AppleScript. And I have to install one hundred functions to use only one. And it’s very hard to clean what I don’t use and keep what I use.

No I don’t have MBS plugins.

Thank you very much for yours answers.

You can use mdls shell:

[code] dim f as new FolderItem
dim sh as new Shell
f=GetOpenFolderItem("")

sh.Execute "mdls -name kMDItemContentType -raw " + f.ShellPath
MsgBox sh.Result[/code]

Kuzey

Do it in whatever way works best for you, but FYI, you can open the MacOSLib project, then copy just the “macoslib” folder into your project. If you don’t use any of it, it will not be compiled into your app. And if you need just one or two functions, it will compile only the methods/classes that it needs. That you have to install 100+ functions doesn’t really impact your final app size.

It would be nice if the IDE can do this as well. Load up the MacOSLib project, select a function or two and select “copy relevant/related code”…paste into a new project and off you go.

Would that even be possible?

I don’t really see the benefit in that, to be honest.

Keeping projects manageable…not having a ton of non needed code to wade through etc.

But that’s just it, it’s all enclosed in the macoslib folder, so there is nothing to wade through unless you need something. And if you need something, you have to wade through it no matter where it is, right?

Well…there’s that I guess.

:slight_smile: To be clear, I wasn’t arguing, just discussing.

Yeah I know, I was wondering if the compiler can do it, then why not the IDE…that’s all :slight_smile:

Thank you. I repeat, macoslib is as long as AppleScript.

I did some try with the mdls shell command. It return a lot of different things when file, but “public.folder” if folder or “public.volume” for volume (which is a Directory in Xojo but not a Package).
Then if my FolderItem is a directory but mdls something else that “public.folder” or “public.volume” then it’s a package. Right ?

Thank you very much.

If you ever want to sell your program on the Mac App Store, or sandbox it, just go the MacOSLib route.

It’s a pain to get clearance for shell or AppleScript work-arounds when you can use native calls to do the same thing.

You can also use kMDItemContentTypeTree which will give you more results like:

[quote] “com.apple.application-bundle”,
“com.apple.application”,
“public.executable”,
“com.apple.localizable-name-bundle”,
“com.apple.bundle”,
“public.directory”,
“public.item”,
“com.apple.package”[/quote]

But yes…Thomas is right, sometimes Apple can make it difficult (not that I have an app ready for release yet)

In what context are you trying to determine if a folder is a package?

Sorry my earlier post may not be so clear, but there are circumstance where you may not need to actually test if a file is a package. For instance if you are trying to read an Apple pages document, you set up the file type so that your app can choose the file and then test to see if the opened file is a folder or not. Apple Pages can create files as either document packages or as flat binary files.

I have a program which synchronize files. The user can choose to manage Package as folder.

I have some Method to open folder, load or save file. I send them a folderItem, if this item is a folder then it’s the default folder (to load or to save in), if it’s a file, then the default folder is the parent file. I had trouble when the file I sent was a package, because the dialog show the package content (as a folder).

And I have another program which give info on a file or folder (modification date, size, and if package or not).

Someone told me that mdls needs Spotlight to be active. Does it work on a volume which is not indexed with Spotlight ?
Thanks