I see that this has been answered previously by Ken T., but I have a case where the code appears to work, and the call to setxattr() returns 0, but the item I want to modify does not change.
Specifically, I'm trying to change the metadata attribute kMDItemDisplayName, and my call looks like this (modeled after the sample posted by Ken T):
[Note: the "name" param below is an NSString *]
rc = setxattr([pathString cStringUsingEncoding:NSUTF8StringEncoding],
"kMDItemDisplayName",
[name cStringUsingEncoding:NSUTF8StringEncoding],
[name lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
0,
0);
Doing an mdls on the file in question shows that the kMDItemDisplayName attribute is present, but I can't get it to change to anything other than the actual file name (which I assume is the default behavior).
Am I misunderstanding something about how setxattr() is supposed to work?
Any help very much appreciated.
Oh, BTW, why am I trying to do this? It appears (from examining how Bare Bones' Yojimbo does things) that Spotlight uses the kMDItemDisplayName value to list files in the Spotlight search results menu in the finder, which is something I'd like to implement in my app.
Thanks!
Heyyyy... wait a minute...
From the command line, doing xattr -l shows that as far as xattr knows, there is an attribute called kMDItemDisplayName, and it is what I set it to be... However, mdls on the same file still shows the kMDItemDisplayName attribute as the file name.
Do I need to be asking about Launch Services instead of xattr stuff??
OK. After hunting around a bit more and reading more Apple documentation I realized what I need to do. I'm answering my own question in the hope that this information may be of some assistance to someone else down the line.
Because I had to write my own mdimporter to support my app's file format, I thought I'd try adding the kMDItemDisplay name item to the metadata store at metadata import time.
To my amazement and delight, it worked on the first try!
So, the answer is, if you want to overwrite or add custom kMDItem* types, you do so at metadata import time, using a Spotlight importer.
Hope that someone finds this helpful!
Related
feel free to edit my question if this explanation seems not relevant to it.
As it is written in my question, I'd like to know what is returned by the function arguments() of the QCoreApplication. In fact, I know that the first argument (.at(0)) will be the name of my application. My problem is, when I tried to open a file by double-clicking it, I thought that i could get the file name with QCoreApplication::arguments().at(1) but it doesn't seem to be the case : the length of the list returned is still 1, and it is (of course) my application name. As a consequence, my application starts but without opening the file... And I don't know where to retrieve the name when I double-click it.
Basically, my question is to know what the double-click is doing on OSX, in reference to the command line.
Note : it happens only when I try to open a file by double clicking it or doing right-click->open with. When I open a file if the application is running, it works.
Thanks!
We have been using Shell32 Folder.GetDetailsOf(folderItem, column) to get file details and extended file details of different files. Unfortunately this breaks between OS versions since the column numbering changes, as can be seen from this code example (no relation to our project).
I can't seem to find the correct way to get extended file details which do not break this easily, and no way to (non-hackily) find out the correct column numbering. So the question, how is this done in the correct way?
(Edit: more specifically, the information we read out is audio, video and image information such as size, fps, bitrate, and so on.)
Use FolderItem2.ExtendedProperty to get the property you want. See this answer, although that answer does it the hard way (via the fmtid). Easier is to use the canonical name, "System.Author" instead of the ugly GUID.
I'm trying to create a new input method using Input Method Kit. The documentation is very lacking, but I believe I'm setting the project up correctly and I place the input method into ~/Library/Input Methods after building it. However, I see strange behavior when looking at the list of input sources in Language & Text preferences.
The NumberInput sample seems to work fine for me, and there are no differences in my new input method that I can find, aside from the values for tsInputMethodIconFileKey, InputMethodConnectionName, InputMethodServerControllerClass, and CFBundleIdentifier in Info.plist. But I'm seeing these issues:
When I use my desired bundle identifier for the app, nothing shows up in the list. (This bundle ID doesn't exist anywhere else on my system.)
Changing the bundle identifier to be the same as the NumberInput sample makes it show up in the list, but when I select it, it sometimes duplicates entries in the list, and generally behaves weirdly.
As I make slight modifications to the bundle identifier, it seems to behave normally, but once I change it back to the original identifier (the desired one) it disappears from the list.
If I quit the process associated with my input method, selecting it in the menu again doesn't relaunch it.
Does anyone have any idea what's going on? Apple's documentation for IMKit is nearly nonexistant and it doesn't seem like many people have documented their own attempts at making input methods. Is there something I'm missing?
Thanks in advance!
P.S. Yes I've tried logging out and back in and even restarting my computer, nothing seems to significantly change the behavior I mentioned above.
This worked for me. Try this: make sure your bundle identifier contains "inputmethod" somewhere in the path. Example "com.blugs.inputmethod.IPAPalette". Yes AFAIK it's totally undocumented. Yes the documentation is awful. Hope this helps! Cheers.
The accepted answer here is very useful, adding .inputmethod. to your Bundle ID.
I'll add that I found a bit of documentation for this in TextInputSources.h, which contains a large number of comments and documentation not found in the Input Method Kit overview docs. Worth a read.
Carbon > Frameworks > HIToolbox > TextInputSources.h
In the Info.plist file, the value for the CFBundleIdentifier key must be a string that includes ".keyboardlayout."; typically this might be something like "com.companyname.keyboardlayout.MyKeyboardLayouts" (Before Leopard, it was required to be a string that began "com.apple.keyboardlayout", even for keyboard layouts not supplied by Apple).
and
If this key is not specified, an InputSourceID will be constructed by combining the BundleID with an InputModeID suffix formed by deleting any prefix that matches the BundleID or that ends in ".inputmethod."
Please consider the following problem.
I'm writing a quick Manipulate[] program to display a ton of information, but am running into problem with the unicode. Here is what I currently have as input and output:
Manipulate[
request = filenumber <> "*";
filenames = FileNames[request];
display = Import[type, "List"];
Short[display, 25]
, {filenumber, "001", InputField}, {type, filenames, PopupMenu}]
The problem is that the French-language accents are showing up oddly. The quick workaround I thought of was to change my code to Import[type,"Plaintext"]; which works, but then displays the information in list form, like so:
What would you suggest as a way to get the clarity of the second example with the straightforward list format of the former? So that it wraps on the line rather than having a line break after each entry.
As an aside - probably just as important as the actual question itself - could anybody explain the rationale behind why importing as a "List" distorts the unicode? I've had a lot of trouble working around this, and understanding the underlying behaviour might help me move forward quicker.
Although Import does not have options associated with itself, it takes options relevant to the format being imported. Specifically see the Options section of ref/Format/List for the list of options.
In the case at hand, you can indicate the file encoding with CharacterEncoding->"UTF8":
Import[filename, "List", CharacterEncoding -> "UTF8"]
Can someone offer some advice on how to get started with mathematica packages?
I can save the following in a file named "Foo.m". When I run the input cell in that file, I can see the effects reflected in $ContextPath variable.
BeginPackage["Foo`"]
bar::usage = "barfunction";
Begin["`private`"]
bar[w_] := w;
End[];
EndPackage[];
However, in my notebook I have the following:
#include<foo>
SetDirectory[ToFileName[{$HomeDirectory, "My Documents", "mathematica"}]];
Needs["Foo`"]
$ContextPath
But the needs call is failing for some reason, and the $ContextPath remains unchanged.
Edit
I believe that I've got a partial solution working now, the cell in my file wasn't marked as an initialization cell - and whilst I can now <<Foo', Needs["Foo"]` still isn't working correctly.
Check to make sure the saved file, "Foo.m", is on your $Path, which tells Mathematica which directories to look in when trying to load packages, much like the PATH environment variable in Unix or Windows.
EDIT: $ContextPath won't be changed unless there's an actual BeginPackage statement (or you manipulate it directly using Set or Block or something).
EDIT the second: One thing to check is what
FileNames["Foo.m", $Path]
returns. What you're describing does sound a little strange, though.
Either form should work. When a file is loaded using Get (or <<) or Needs, the directory on the top of the DirectoryStack[] is searched first, and then the $Path is searched. (SetDirectory does not change $Path, so FileNames["Foo.m", $Path]won't find Foo.m.) However, FindFile by default searches Directory[] and $Path. You can test it by doing the following:
FindFile["Foo`"]
SetDirectory[<Foo dir>]
FindFile["Foo`"]
it should return
$Failed
<Foo dir>
<Foo dir>/foo.m
If FindFile can find Foo.m then Needs should be able to find it. In general, I put my packages in $UserBaseDirectory/Applications, and Needs picks them up just fine.