Hi, just got specialfolder.ApplicationData to work for saving and reading a prefs file…
But, the pref file includes a name of a folder. If that folder is inside my user, all ok. But if that name is /Volumes/ExternalDiskName1 then it will not work at all.
So it looks like anything outside my user, or anything outside what goes into my container is a NO-GO. Is it so ?
How am I then going to store information about what diskdrive that was last used in my app. ???
That sounds very odd. So is the path that is stored in the prefs file stored after the user has saved a file to a particular location in your app so next time they save you have the path?
I wouldn’t have thought it would matter what is in your prefs files in terms of path references. I though sandboxing was about making sure your app did not access locations it was not supposed to but if your user saves or opens from wherever they want any you save that location to your prefs file then you should be ok if your app does not access it directly.
Yes, my app only stores the location the user last used.
Upon starting the app the next time, I would like my app to use that location and immediately do a new scan.
But if the location is a /Volume/diskName1 then it will not work. Only stuff inside the user will work… Thats really irritating.
But, that is the only way for now I guess.
Read apple sandbox guide at HERE it states under the heading:
[h]Container Directories and File System Access[/h]
User-specified files. A sandboxed app (with an appropriate entitlement) automatically obtains access to files in arbitrary locations when those files are explicitly opened by the user or are dragged and dropped onto the application by the user.
Yes, but that is only when the user does it. But not when the app does it for you.
And that is the problem.
There must be a way. I have apps from the MAS which I can click on the FILE >> OPEN RECENT menu item and the app opens the file. Open recents would be stored in the apps prefs file and when you click on the open recent item it is the app doing the opening of the file not me doing OPEN and navigating to the file. I have just tested this and stored a file to /www it would not let me save to / fair enough but /www is not in my user folder although I as a user do have RW permission to /www.
How do you open it then ?
window1.gStartFolder = GetFolderItem(sti, folderItem.PathTypeNative)
gStartFolder is my global folderItem
sti is the stored path in my textfile
Well, this is the thing I did:
f2 = GetFolderItem(sti, folderItem.PathTypeNative)
window1.gStartFolder = f2
but now I changed it to the other one… just to check
Sorry, I mean I have apps I have purchased from the MAS which are sandboxed which work outside the user folder.
However, yes I would do what you have suggested if I was writing this.
Helge, read about Powerbox and File System Access Outside of Your Container further down the page on the link I gave you above. I think this is your answer
Powerbox uses NSOpen and SAVE, or the others listed, but not /Volumes
I don’t think it matters if it on an external drive etc etc. You need to have an entitlement to a file system object outside your sandbox container. I am certain this will answer your question.
[h]Two Distinct Types of Security-Scoped Bookmark[/h]
Security-scoped bookmarks, available starting in OS X v10.7.3, support two distinct use cases:
An app-scoped bookmark provides your sandboxed app with persistent access to a user-specified file or folder.
For example, if your app employs a download or processing folder that is outside of the app container, obtain initial access by presenting an NSOpenPanel dialog to obtain the users intent to use a specific folder. Then, create an app-scoped bookmark for that folder and store it as part of the apps configuration (perhaps in a property list file or using the NSUserDefaults class). With the app-scoped bookmark, your app can obtain future access to the folder.
There are several ways to do this, bearing in mind that what you need to so is to retain access to the file throughout app restarts.
Use NSDocumentController to manage recent items. Search the forums for the code I posted.
Use NSDocuments and Lion’s Resume, this is a lot of hard work, and the second preferred Apple mechanism. I’ve not shared the code for this because it requires a complete app re-write.
The last solution, I’d ever recommend is the flaky and problematic Security Scoped Bookmarks. Search these forums and you’ll find all the reasons as to why I suggest for your own sanity you avoid them, you’ll also find code for them.