If any of you are using my old SandboxSafeRecentItems code, I would advise that you rip that code out, go into the back yard, shoot it, bury it, cover it in salt and burn it. While it does work, it’s an abomination that can cause applications to well up and die. Instead I’d recommend using my nice new shiny “Sandboxing Done Right - Recent Items” code.
Simple, you may or may not know, that I’ve spent literally months of hacking, swearing, cursing, digging and generally tearing Objective-C “Document based applications” apart (not to mention interrogating Apple’s engineers). I’ve done this to figure out why Obj-C Doc based apps are automagically Sandbox safe and why other apps have to hack, slash and suffer to work ‘alright’ (even Obj-C devs have to suffer when not using Doc based apps).
While there are several things that should be done, the easiest to implement is the NSDocumentController. When you use the NSDocumentController to manage the recent items list, the OS will then automatically maintain access to all the files in the list for you. Which means for recent items, no more SSBs, no more requesting & releasing access (before the OS does and then breaks your app).
Literally using the NSDocumentController makes a whole lot of Sandbox headaches go away and as a bonus, files in the Recent Items list also appear in the Dock Menu
I’m including the full source code - for you to prod and poke at. So have fun and save money on aspirin or whatever else you take when your head hurts from banging it against a brick wall.
Thank you. I really appreciate the code, learning alot.
Having some odd behavior with the demo and not sure how to change it. I dropped a couple .webloc files on the listbox and they showed up in all 3 places (listbox, file menu and dock menu). Selecting from the file menu triggers NewDocument but selecting from the dock menu launches the file in Safari.
Then I dropped in a .txt file and it only appeared in the listbox and file menu. After a quit and run the txt file appeared in the dock menu and selecting it triggered NewDocument. The webloc files still launch in Safari though.
Any ideas why the txt file didn’t appear in the dock at first and why webloc files get launched instead of triggering NewDocument?
(This is all from debug runs if that makes a difference)
Files are correctly getting added with noteNewRecentDocumentURL and retrieved with recentDocumentURLs, but the dock-menu’s list is only built the first time it’s shown. Thereafter it’s never updated until the next run. The file-menu’s list stays current.
What can be done to update the dock-menu’s list every time it’s shown? Is it my system: Xojo 13r2, OS 10.7.5, MacBook Pro late 2011?
The “Recent menu” in the menubar is created in Xojo (I haven’t found a way to get the OS to handle the menubar menu), so when you select a menu item from the Xojo menu, the folderitem is opened directly in the Xojo application. The dock menu is all handled by the OS.
I’m guessing here the OS is deciding that .webloc files should be opened in Safari, I’m wonder if you add a file type for .webloc and set up the application so that the app is an editor for .webloc, the OS might then open the files in the app.
As for the file not showing in the doc menu, again this is an OS level issue. I don’t recall seeing any functions for updating the menu when perusing the apple documentation, but then again the Doc menu was a nice surprise addition It does seem to work here on 10.8.4
Yeah, that’s what I was hoping for. Been up and down the NS docs for some refresh menu method. I can’t find any mentions of noteNewRecent not working so I’m guessing the way Xojo manages the dock-menu is better handled in 10.8. Alas, I don’t plan to upgrade until 10.9 when I’ll put your code to use. Thanks again Sam for this.
One thing that is bugging me is this – If there are two items in the recent file list with the same file name but exist in different paths, you can’t tell them apart. Xcode apps deal with it like this:
However, in your current implementation, you get this:
Any idea how to get the Xcode-like behaviour of displaying containing folders for identical filenames?
Wow! I just hit the “like” button in the OP. Unfortunately, I can’t find a “Love” button
I just went to your site. The link in the OP was a dead end. But I see it is available to buy as a plugin of some sort.
But on your site it I noticed it is fairly old. Will it still work with the current version of the Mac OS?
My guess is that it will. Unless lots of the Sandbox policies have changed over the last couple of years.