Open Westacular opened 13 years ago
Thank you, these are very helpful suggestions. I do agree with you that it aids usability for the services menu item name to more accurately reflect the resulting action, but on the other hand having multiple items appear in 10.5 and under might be annoying.
Since most of these changes are isolated to the Info.plist file, do you think you'd mind trying some of them out to see how well they work?
With the current Info.plist, the "NV: New Note With Selection" item in the Services Menu shows up for all file types when using Finder (among other applications). If you try to use it on a non-text file (e.g. a movie file) NV will load/take focus and then silently fail to do anything.
Snow Leopard allows for much more fine-grained and contextual control over when a service item is and isn't relevant, but NV is using the old/deprecated services and pasteboard API. The presence of NSURLPboardType and NSFilenamesPboardType in the service item's NSSendTypes array (without any further contextual information) are basically telling the system that it will accept references to any sort of file.
The solution is to remove those two items from NSSendTypes, and add a NSSendFileTypes array to the service dict, listing the UTIs for filetypes it can accept -- in this case, the same ones listed among CFBundleDocumentTypes (e.g., com.apple.rtfd, com.adobe.pdf, public.text, etc... I'm not sure if there's any need to specify things like RTF and HTML that are subtypes of public.text?)
Or, better yet, split it into three separate services items, one for selected text content, one for importing from URLs, and one for importing files. This can be done purely within Info.plist, and doesn't require any change to the code -- all the services items can still call the same function.
Advantages to this approach:
On that last point, one idea, not sure if it's possible: the file import entry uses NSSendFileTypes and is valid only under Snow Leopard, while the "New Note With Selection" entry stays mostly as it currently is (including NSFilenamesPboardType) but has some added parameters (eg under NSRequiredContext) that tell Snow Leopard the service should only operate on text selections, and not files.
Alternately: given the state of the Services menu prior to Snow Leopard, I question how many people might be using the file-import capabilities of this service on older versions of OS X. You might be able to take a Snow Leopard-only approach to the file import service without anyone noticing.
References: http://developer.apple.com/documentation/Cocoa/Conceptual/SysServices/Articles/properties.html http://developer.apple.com/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/Reference/Reference.html