I am looking for a way to get the application icon from a window id in cocoa. Do you have any pointer for this?
First, use CGWindowListCreateDescriptionFromArray() to get the PID of the owning process (kCGWindowOwnerPID). If this is 10.6, you can then use +[NSRunningApplication runningApplicationWithProcessIdentifier:] to get the application object and then use -icon.
Before 10.6, you need to use GetProcessForPID() to switch to a PSN, use GetProcessBundleLocation() to get the location of the bundle, switch the FSRef into a path string, and then use -[NSWorkspace iconForFile:] to get the icon.
Rob Napier's answer is correct.
In the latest api and in swift language, it should be like this:
let runningApp = NSRunningApplication(processIdentifier: pid_t(the_process_id))
let icon = runningApp?.icon
Related
I am quite surprised I have yet to find an answer to this on the internet.
How do I open a native/default app from my nativescript app?
In this instance I want to open a map application with a location parameter (not sure if it will be a string, coordinates, etc).
You can use utils
var utilsModule = require("tns-core-modules/utils/utils");
utilsModule.openUrl("<< for example: maps short link>>");
In fact it will try to open map link with browser. But android && ios will ask to you “do you want to open it via Maps?” at first.
There may be some plugins for opening via maps directly without any question but I think this way is better (you dont need to install a plugin)
For more info about utils, see that
Trying to whip up something quick and dirty that mass renames and converts files, and having a rubymotion license I thought why not use it to make a simple app that you can drag and drop instead of some batch file.
However I am having trouble detecting the drag event, can't seem to find information about how to do this in rubymotion, I've only used rubymotion to do iOS apps, and find myself lost.
Any help would be appreciated.
Have you started on any Cocoa tutorials? Anything written in Objective-C can be ported easily. I would start here: Drag and Drop Programming (developer.apple.com)
If you want to support dragging onto the dock icon, you'll need to modify the project's supported document types, and I'm not sure how to do this (check rake config, it might give a clue). You'll eventually need to implement this method, too:
def application(sender, openFile: path)
# sender is an NSApplication, path is NSString
true # or false
end
You need to add something like :
app.info_plist['CFBundleDocumentTypes'] = [
{'CFBundleTypeRole': 'Viewer', 'CFBundleTypeExtensions': ['mp4','m4v','avi','*'] } ,
{'CFBundleTypeRole': 'Editor', 'CFBundleTypeExtensions': ['txt'] }
]
to the setup block in the Rakefile
And add the following method to the AppDelegate class in app_delegate.rb
def application(sender, openFile: path)
true
end
Do a rake clean before you do rake build and you should be good to go.
Note that the application method gets called for each file that you drop onto the Application icon. path contains a string of the dropped files path.
Qt version 4.8.1, building for Windows, I'm trying to get accessibility information to work correctly for some buttons I have.
I have a QPushButton in my main window, which has an icon, thusly:
m_restartBtn = new QPushButton();
QPixmap rpm(":/images/Restart32x32.png");
QIcon ricn(rpm);
m_restartBtn->setIcon(ricn);
m_restartBtn->setIconSize(rpm.rect().size());
// put it in a box in the main layout
QHBoxLayout *buttonBox = new QHBoxLayout;
ui->mainLayout->addLayout(buttonBox);
buttonBox->addWidget(m_restartBtn);
Now that button shows up correctly, and if I hook up the signals it works fine. But when I use the 'inspect.exe' (from the Win 7 SDK), I see that the button shows up, but has no name.
If I use setText instead of putting in an icon, the accessible name shows up correctly, but of course, I'm seeing text, not my icon. If I do both, then the accessible name works fine, but I get the text on screen, as one would expect.
I tried setObjectName and setWindowTitle just for laughs, and they of course didn't work.
Is there a proper way to set the accessible name for a QPushButton that only displays an icon?
My immediate goal is to remotely control the application for accessibility purposes. But I'd like the work to do double duty and get me full accessibility at the same time, so I don't have to do a separate effort later for accessibility.
You can use QWidget::setAccessibleName(const QString &name).
QPushButton *button = new QPushButton(this);
button->setAccessibleName("name");
Is this what you were looking for?
I've read all the tickets about this issue, but I still don't get it right. I have a non-document OSX app (for OSX Lion and MountainLion). I want this app to export and import custom data, associated with a custom file extension ".iobs". Internally, these files are just data archived with [NSKeyedArchiver archivedDataWithRootObject:], and saved onto the disk with the "iobs" extension.
So, my check list is this:
1) Export mechanism: checked. My app create correctly .iobs files. If I run "file <filename.iobs>" in the Terminal, I get "iObserve_exportedItems.iobs: Apple binary property list"
2) Declaration of an exported UTI, checked. As shown in the image below. I did NOT declared a custom Document type, since it I never use NSDocument inside my app, and there is no point. Anyway, I already tried and failed. I've tried also different combinations of "Conforms To" entries, but with no success.
3) Is there any 3rd point??? Do I need to start my app once to let the system know? I just ran it in Debug from Xcode so far, and this has no effect. So I guess my Info.plist is wrong, but I filled it from within Xcode4 interface, so???
Thanks for any help, hint, question, suggestion.
Ok, so apparently, I do have to declare a document type even if I don't specify a document class. See the attached screenshot. Note that leaving only the Document UTI doesn't work. I do need the two (exported UTI and document type). Note also that if I say it conforms to com.apple.binary-property-list, I don't have the right icon.
And for those who wonder, there is nothing to do to "register" a type (and its subsequent changes) apart from launching the app once.
How can I drop a file(or select to open it in Finder) of a type specified in the Info.plist onto my dock icon and then calling a method with the full path of the file?
If you've set up your Info.plist's CFBundleDocumentTypes array properly (either 'LSItemContentTypes' or 'CFBundleTypeExtensions'), then you just need to set up an NSApplication delegate and implement the delegate method, application:openFile:.
If you're expecting multiple files to be dropped at once, implement application:openFiles:.
For promised files (NSFilesPromisePboardType/kPasteboardTypeFileURLPromise) see Dropping promised files on to application icon in Dock.
Here's an updated solution for Xcode 5.
In AppDelegate.m
-(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
NSLog(#"%#", filename);
return YES;
}
And in Xcode setup Document Types under Project > Targets > Info:
Check settings in Info.plist in case you have an empty 'Document Content Type UTIs' array which should be filled out properly or else deleted.
Your Info.plist should look something like this:
On current systems you can use a UTI instead of the old-style four-char types (such as fold above). In Xcode's document type editor, make a new type with:
Name: Folder
Identifier: public.folder
public.folder is a subtype of public.directory. public.folder matches directories that appear as such to the user, i.e. not packages like .app wrappers.
Select your application in the target group of the side pane and use get info. Then in the new window select the properties tab to add a new document type. Name it "Folder" for convenience and the OS Types needs to be "fold"; the store type and role you can leave as is.
If you're actually making a document-based app, setting it up to give you the path will have you doing far more work than you need to. Simply use the document-based application template. The document controller will create an instance of the right class for you; you need only write that class.
An application you create this way will handle file drops (by opening them as documents) for free.