folder that opens an app

hi there, i was wondering if this is possible…
to have a folder that the app creates on the desktop and when it is opened in the finder or double clicked it opens my app.
as i want to store things in this folder just like a normal folder but i want my app to be running when it is opened.
thanks in advance for any help or ideas.

You could make it a bundle, but that wouldn’t allow users to easily access the files within the folder.
My other thought would be a folder action that launches the app, but I don’t have any experience with folder actions or how they work.

I do not know a way to open an app when a folder is open.

But you could create a document with a folder icon, and an extension that your app can open. Add it to your project.
Then at first launch of your app, you copy that document to the desktop.
When the document is opened, it launches your app, and in Application.OpenDocument, open the folder you want (could be set aside in your app SpecialFolder.ApplicationData) with FolderItem.Launch.

For the user, opening the document will look as if he was opening the folder, while your application is launched.

Paul, as Tim suggestions, Folder Actions will let you carry out various actions when a folder is opened (anything you can do in AppleScript really), including launching an app. This method would mean you’d manually create the folder and set up Folder Actions yourself - I don’t know if this is appropriate for whatever you are doing.

Check it out by right-clicking on a folder and choosing Folder Actions Setup. If you have trouble, post back here.

There is yet another, simpler approach that can work :

  • Create a shortcut to your app
  • Change its icon to that of a folder
  • Add it to your project
  • Copy it from your app bundle to SpecialFolder.Desktop upon first run.

When the user opens the shortcut that looks like a folder, it launches you app which in turn opens the folder.

Tricking your users really isn’t the best way to go about software development.
(Also that seems like quite a bit more work than a folder action)

In other news, I haven’t yet been able to determine if there’s a way to assign folder actions from code instead of having a user do it them self.

On OS X Tim’s suggestion of making you “file format” a bundle is probably the right way to go
See “Document Packages”
https://developer.apple.com/library/mac/documentation/corefoundation/conceptual/cfbundles/DocumentPackages/DocumentPackages.html#//apple_ref/doc/uid/10000123i-CH106-SW1

Tim[quote=78658:@Tim Parnell]In other news, I haven’t yet been able to determine if there’s a way to assign folder actions from code instead of having a user do it them self.[/quote]

This is specifically disallowed by design, going all the way back to OS 9. Because the user cannot cancel a folder action, or even determine whether one is attached to a particular folder, Apple designed it such that only the user can attach folder actions to a folder.

Also, as far as I can recall, Folder Actions are not respected on removable drives. This prevents an opportunity for someone to write a self-propogating action - i.e., a Folder Action worm or virus.

[quote=78658:@Tim Parnell]Tricking your users really isn’t the best way to go about software development.
(Also that seems like quite a bit more work than a folder action)

In other news, I haven’t yet been able to determine if there’s a way to assign folder actions from code instead of having a user do it them self.[/quote]

Programming is all about getting a given result by offering the user a simple method to get to what he wants. If he wants to open a folder, what I describe is doing exactly that. Tricking the users would mean doing something else. I find your judgement unnecessarily harsh and inaccurate :frowning:

Because you intend to use folder action, which you recognize not being able to apply, does not discount other methods. Especially when what you want to do it is not possible.

The bundle file format proposed by Tim is yet another way of getting to the desired result, that implies presenting a document which triggers the expected result. Are you calling that trickery as well ? Thinking out of the box and being intellectually adaptive has always been the way to advance software development. Try to be more open.

I think the bundle file format is best. Give it a folder like icon and have your app open a window when you double click it.

Like the “iPhoto Library” item in the pictures folder which opens iPhoto.

[quote=78715:@Christian Schmitz]I think the bundle file format is best. Give it a folder like icon and have your app open a window when you double click it.

Like the “iPhoto Library” item in the pictures folder which opens iPhoto.[/quote]

As usual with Apple documentation, the link provided by Norman leads to a nightmare of convoluted information that feels like sinking in yoghourt. I tried to google CFBundleDocumentTypes and found absolutely no description of the keys to enter in info.plist to register any particular file or bundle type.

A sample example showing how to modify the plist to register a particular file or bundle type would definitely help.

Once again, for lack of clear, step by step indications about how to proceed, grand ideas and pompous programming concepts end up in the sinkhole of obscurantism :frowning:

I can’t remember where I got this piece of code but it works in creating a folderitem as a package or bundle.

[code]Sub CreateAsPackage(extends f As FolderItem) As Boolean
const kHasBundle = &h2000
f.CreateAsFolder
dim fl as integer = f.GetFolderFlagsMBS

if fl < 0 then
fl = kHasBundle
else
fl = BitwiseOr(fl, kHasBundle)
end if

dim e as integer = f.SetFolderFlagsMBS(fl)

if e = 0 then
Return True
else
Return False
end if

end Sub [/code]
This uses the MBS suite so you will need a licence.

I tried to reverse engineer the info.plist in iPhoto and thought for a while that had found what to do, but after experiment, it does not appear to be working reliably. So much for that.

I also tried to place a shortcut in a project and copy it to the desktop. No luck. It opens the content of the app.

The only way I could make a folder open at the same time as the app is to place the app itself on the desktop, with a folder icon.

When clicked, it opens a folder and displays its window.

If the app is not for the MAS, directing the user to place the app on the desktop instead of the Applications folder should not be too much of a hassle.

Copying the app from the bundle to the desktop in case of a sandboxed application will require prompting the user to it through as “Save as…” dialog. And because copying a whole bundle is not easy, the solution lies probably in storing a zip fie into the project and extracting it to the desktop through a shell.

The alternative is to load on aspirin and dive into the nightmarish Apple documentation until, after hours of boring and confusing reading, one finds in a well-hidden corner, the way to have a document open an app. I was not up to that cruel challenge. Sorry :wink:

The original question has been rather buried here, but what you are looking for is called a package. Apple’s documentation is actually quite clear on how they are structured; I suggest that you take a look at it.

Sure. “It’s easy”. “It’s quite clear”. “Why can’t you understand” ?

Does not help :confused:

you can go here:
https://developer.apple.com/library/mac/documentation/corefoundation/conceptual/cfbundles/DocumentPackages/DocumentPackages.html#//apple_ref/doc/uid/10000123i-CH106-SW1

Michel, I don’t think anything I could suggest would meet your standards. I hope the original poster can find value in what Christian and I are suggesting.

[quote=78728:@Simon Berridge]I can’t remember where I got this piece of code but it works in creating a folderitem as a package or bundle.

[code]Sub CreateAsPackage(extends f As FolderItem) As Boolean
const kHasBundle = &h2000
f.CreateAsFolder
dim fl as integer = f.GetFolderFlagsMBS

if fl < 0 then
fl = kHasBundle
else
fl = BitwiseOr(fl, kHasBundle)
end if

dim e as integer = f.SetFolderFlagsMBS(fl)

if e = 0 then
Return True
else
Return False
end if

end Sub [/code]
This uses the MBS suite so you will need a licence.[/quote]

this seems to work well, but when i open the package/folder my terminal opens up. not sure how to make my application open up.

ok, got it to work with the above code and i just gave the package a file extension from my filetypes and wola.
thanks heaps guys.

[quote=78728:@Simon Berridge]I can’t remember where I got this piece of code but it works in creating a folderitem as a package or bundle.

[code]Sub CreateAsPackage(extends f As FolderItem) As Boolean
const kHasBundle = &h2000
f.CreateAsFolder
dim fl as integer = f.GetFolderFlagsMBS

if fl < 0 then
fl = kHasBundle
else
fl = BitwiseOr(fl, kHasBundle)
end if

dim e as integer = f.SetFolderFlagsMBS(fl)

if e = 0 then
Return True
else
Return False
end if

end Sub [/code]
This uses the MBS suite so you will need a licence.[/quote]
I remember where I got the code from - Christian Schmitz himself!

Sorry, Christian…