Get list of file extensions of public.movie UTI - objective-c

I'm trying to create an NSOpenPanel that only looks for movie files. I'd like to do this by looking up the registered movie file extensions using the public.movie UTI. Can anyone help me out?

You don't need to retrieve the file extensions of the UTI: you can use the UTI directly.
According to the documentation, the method setAllowedFileTypes: of the NSSavePanel class (superclass of NSOpenPanel) accepts UTIs as well as file extensions.
So this should work, without having to wonder about associated file extensions.
[yourOpenPanel setAllowedFileTypes:[NSArray arrayWithObject:#"public.movie"]];

Related

path of suporting files in OS X program?

I need some help for my OS X program.
I need the URL of a file inside the supporting files.
I have an array in which I save URLs from images and add them to a table view and if no images are chosen I want to add a question mark image (it is called "bild.jpg")
This bild.jpg is inside the supporting files but for later use I can't just save the name of the image because the array stores also URLs.
I need to have the URL of that image in the supporting file because it's easier to use the array for image initialization.
Is there a function to get the path or is there a standard path to the supporting files? I already search on the net but couldn't find anything that could help.
You seem to be talking about the application bundle and its resources directory rather than, say, a subdirectory in ~/Library/Application Support/..., in which case you probably want something like:
[[NSBundle mainBundle] URLForResource:#"bild" withExtension:#"jpg"]
(See the documentation for NSBundle.)

iOS custom email attachment handling in iOS6

My app allows for a text file to be emailed to other users with or without images and audio. When there's no images or audio, then the app sends the text file "as is" with a custom extension (e.g. text.xxx). When there's audio and images, the app zips the text file along with the images and audio into a file named something like text.xxx.zip.
Prior to iOS 6 this worked fine. Pre iOS 6, the app was given the URL of the text.xxx.zip file. Now, with iOS 6, it appears that the file is already unzipped by Mail, and only the text.xxx is sent to the openURL handler.
Does anyone out there have any experience with this? Suggestions for a better approach? I'm thinking I'll need to come up with a unique extension for the zipped case...
So after pounding my head on this for the last 24 hours or so, this is what "solves" the problem:
1) Change any existing attachment filenames from test.xxx.zip to test.zip. It looks iOS6 Mail is assuming that anything of the form filename.xxx.zip, is really just a compressed version of filename.xxx. (Maybe that's a standard somewhere?) Also noted that if I changed the filename to test.yyy.zip it then said it couldn't open the attachment. (presumably since no one registered for the ".yyy" extension).
2) Rewrite code to not use .zip extension in the future to prevent similar issues.
I also discovered that for multiple document types (e.g., .xxx, .zzz) you must specify a different mime type for each in the UTI declaration - otherwise Mail appends the first UTI extension it finds to the object and then calls openURL. So, in other words, if you're set up to handle a flat file (.xxx) and a zip file (.zzz), but you use the same mime type (e.g. application/myappname) and "xxx" is defined first, when openURL is called for your file "test.zzz", it will actually pass it to openURL as "test.xxx".

how to open an apple unsupported file in our ipad app

i need to open an Apple unsupported file in my ipad app using "Open In" feature. The file extension in ".lasso" . I said that file is unsupported by Apple, because i cant find it description in Apple System-Declared Uniform Type Identifiers.
I was try to solved that using CFBundleDocumentTypes in info.plist, but i still can not open it. i was write this in my plist :
but when i try to open a .lasso file from another apps, there always show an alert "Can not open this file in another apps".
do somebody know how to solved it?
You need to create your own UTI for your file type, something like com.yourcompany.lasso. Your Info.plist is claiming to export the public.plain-text UTI which of course already exists. You would also list the pre-existing UTIs that your new UTI conforms to. You don't show what's under the "Conforms to UTIs" key in the screenshot, but it should apparently be public.plain-text if .lasso files are indeed plain text. (If there's a specific encoding for .lasso files, such as UTF-8, you should consider something more specific, such as public.utf8-plain-text.)
Also, you should either have a custom MIME type or not use one at all. You don't want to redefine the "text" MIME type to suggest that all data streams of that type are Lasso files, do you?
And why are you using all-caps for "LASSO". I assume that, in real use, files will have an extension in lowercase like ".lasso". Right?

How to change the icon of file in MacOS in Objective-C?

My program for MacOS is creating the alias to another file and I want this alias to have some designated icon. How can I do it with Objective-C, preferably in Cocoa?
You can use NSWorkspace, which has a method for doing this:
//anImage is an NSImage object and
//pathToFile is a path string
[[NSWorkspace sharedWorkspace] setIcon:anImage forFile:pathToFile options:0];
This will save the icon data to the file's Resource Fork. These days Mac OS doesn't use actual resource forks, so the image is stored in an HFS extended attribute named com.apple.ResourceFork.
Extended attributes are filesystem metadata attached to a file. You can see the extended attributes attached to a file using xattr and related commands.
Note that extended attributes are only guaranteed to be reliable on HFS+ file systems, if the file is located on a file server that doesn't support file metadata or on an external drive with a non-HFS file system, the icon may not be written.

Opening a file using ScriptingBridge

I have an AppleScript that I am trying to convert to ScriptingBridge. Since my application is a C++/Obj-C application, ScriptingBridge is much easier to use and quite a bit faster (not to mention I hate dynamically building AppleScripts).
The AppleScript sends a message to Photoshop to open a file. The file parameter is sent as an alias, but ScriptingBridge imports the parameter as an id. I don't know what Obj-C object I should pass in?
I've tried passing an NSURL and an NSString (probably incorrectly :-P), but to no avail. Any suggestions on what I should be passing for the file alias?
The short answer is that you can't open documents in Photoshop with Scripting Bridge.
Apple's docs really spell it out like it is. All classes must have a container, which is a mutable array, that they need to be added to before they can be acted upon, as shown in the generated header...
#interface photoshopCS4Application : SBApplication
- (SBElementArray *) documents;
- (SBElementArray *) fonts;
- (SBElementArray *) notifiers;
... and that is the complete list of top-level containers available to us. The open command requires a photoshopCS4OpenOptions to be generated and populated. Because the API doesn't expose the array to store the newly created photoshopCS4OpenOptions object, we can't use a newly created photoshopCS4OpenOptions object. Therefore we can't make a target document and by extensions can't use the open command in Scripting Bridge. The same can be said of all the commands that require some kind of options object.
The only workaround that I have sorted out is to either open a document with native Applescript called from Cocoa or objc-appscript, and then parse the documents array looking for the one just opened. It's not ideal, but then neither is Scripting Bridge because it requires application developers write their scripting APIs in a very specific way that is not native to the OSA framework.
If your program is such that opening a Photoshop document can be executed outside your AppleScript script/Scripting Bridge code, Cocoa provides a method to open files with a specific application:
[[NSWorkspace sharedWorkspace] openFile:#"/Users/bavarious/Desktop/test.psd" withApplication:#"Adobe Photoshop CS4"];
or, if you want to use the default application that handles that file type, you can drop the application name altogether:
[[NSWorkspace sharedWorkspace] openFile:#"/Users/bavarious/Desktop/test.psd"];
Consider Appscript. http://appscript.sourceforge.net/
Here's the code using that:
APApplication *adobePhotoshopCs4 = [APApplication applicationWithName: #"Adobe Photoshop CS4"];
id result = [[adobePhotoshopCs4 open_] send];
(Note, I'm not a Cocoa programmer - I mainly use Appscript with Python but Appscript comes with ASTranslate which translates Applescript into Python, Ruby or Obj-C and that's the output - but I've found there are subtle mistakes in the past sometimes with the translator)