I'm trying to use this method on an NSObject in a macOS Command Line Tool.
https://developer.apple.com/documentation/objectivec/nsobject/1416176-performselector?language=objc
This works fine in a normal app but when I try to use it in a Command Line Tool nothings happens. I'm keeping my app running by using dispatch_main(). What else do I need to do to have this method working on an NSObject?
int main(int argc, const char * argv[])
{
#autoreleasepool
{
// ...
}
dispatch_main();
return 0;
}
After "upgrading" to macOS High Sierra it seems that some code that used to work does no longer. My goal here is just to list out the windows owned by an application. Here is an example:
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#import <ApplicationServices/ApplicationServices.h>
int main(int argc, const char * argv[]) {
#autoreleasepool {
pid_t myPID = 311;
AXUIElementRef appRef = AXUIElementCreateApplication(myPID);
CFArrayRef windowList;
AXUIElementCopyAttributeValue(appRef, kAXWindowsAttribute, (CFTypeRef *)&windowList);
}
return 0;
}
The issue here specifically is that windowList does not get contain anything no matter what I do. I have tried multiple PIDs, building/running both debug and release builds, and running them with sudo as well.
Any ideas?
Below is my code:
#include <opencv2/opencv.hpp>
using namespace cv;
int main (int argc, char** argv) {
Mat image;
image = imread("/Users/Desktop/lena.jpg", 1);
namedWindow("Display Image", WINDOW_AUTOSIZE);
imshow("Display Image", image);
waitKey(0);
return 0;
i run it, but i get the following error
How can I resolve this issue?
Hi i`m starting to develop in objective c, but when I try to show a simple message , thereĀ“s no output i only have this class main.m
import
int main(int argc, const char * argv[])
{
#autoreleasepool {
// insert code here...
NSLog(#"%#",#"Hello, World!");
}
return 0;
}
This should be working, is your debugger showing?
Forget it it was the keyboard that was bad configured.
Why doesn't the function displayChanged get fired in the following code?
#import <Cocoa/Cocoa.h>
static void displayChanged(CGDirectDisplayID displayID, CGDisplayChangeSummaryFlags flags, void *userInfo) {
NSLog(#"%#, %#", displayID, flags);
}
int main(int argc, const char * argv[])
{
#autoreleasepool {
CGDisplayRegisterReconfigurationCallback(displayChanged, NULL);
CFRunLoopRun();
}
return 0;
}
I'm physically removing (and plugging in) my external display, but the function is never run.
Why?
Just found the solution on this other question
Before calling CFRunLoopRun you have to call NSApplicationLoad to establish a connection with the window server. This is the fixed code for the original question:
#import <Cocoa/Cocoa.h>
static void displayChanged(CGDirectDisplayID displayID, CGDisplayChangeSummaryFlags flags, void *userInfo) {
NSLog(#"%u, %u", displayID, flags);
}
int main(int argc, const char * argv[])
{
#autoreleasepool {
CGDisplayRegisterReconfigurationCallback(displayChanged, NULL);
NSApplicationLoad(); // establish a connection to the window server. In <Cocoa/Cocoa.h>
CFRunLoopRun(); // run the event loop
}
return 0;
}
I couldn't get CGDisplayRegisterReconfigurationCallback to work, so I used distributed notifications instead:
int main(int argc, const char * argv[]) {
#autoreleasepool {
[[NSDistributedNotificationCenter defaultCenter] addObserverForName:#"com.apple.BezelServices.BMDisplayHWReconfiguredEvent" object:nil queue:nil usingBlock:^(NSNotification *notification) {
NSLog(#"Displays changed!");
}];
CFRunLoopRun();
}
return 0;
}
If you're using AppKit (and have a running NSApplication event loop), you can listen for the NSApplicationDidChangeScreenParametersNotification notification. Or, you can implement the -applicationDidChangeScreenParameters: method in your application delegate, which amounts to the same thing.