nsrunningapplication

Inject keyboard event into NSRunningApplication immediately after foregrounding it

天大地大妈咪最大 提交于 2020-01-30 10:50:46
问题 I am trying to bring to foreground a NSRunningApplication* instance, and inject a keyboard event. NSRunningApplication* app = ...; [app activateWithOptions: 0]; inject_keystrokes(); ... fails to inject keyboard events, but: NSRunningApplication* app = ...; [app activateWithOptions: 0]; dispatch_time_t _100ms = dispatch_time( DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC) ); dispatch_after( _100ms, dispatch_get_main_queue(), ^{ inject_keystrokes(); } ); ... succeeds. I imagine it takes a

Inject keyboard event into NSRunningApplication immediately after foregrounding it

≯℡__Kan透↙ 提交于 2020-01-30 10:48:06
问题 I am trying to bring to foreground a NSRunningApplication* instance, and inject a keyboard event. NSRunningApplication* app = ...; [app activateWithOptions: 0]; inject_keystrokes(); ... fails to inject keyboard events, but: NSRunningApplication* app = ...; [app activateWithOptions: 0]; dispatch_time_t _100ms = dispatch_time( DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC) ); dispatch_after( _100ms, dispatch_get_main_queue(), ^{ inject_keystrokes(); } ); ... succeeds. I imagine it takes a

NSRunningApplication, return list of recently used applications?

一个人想着一个人 提交于 2020-01-29 09:39:30
问题 I'm trying to get a list of the most recently used applications. NSWorkspace returns a list of active applications and I can sort them on a few options using NSRunningApplication . see list below: - launchDate - finishedLaunching - processIdentifier I don't want the launch date but the most recent 'active' date (like the way cmd - tab sorts). Does anyone know the solution for this? 回答1: There is no documented way of doing this that I'm aware of, but I wrote exactly what you are asking for

How to get the PID from a ProcessSerialNum in OSX 10.9?

十年热恋 提交于 2020-01-13 10:16:15
问题 GetProcessPID was marked deprecated in OSX 10.9 along with the note: Use the processIdentifier property of the appropriate NSRunningApplication object. The problem is the constructing class methods for NSRunningApplication do not have a way to get a NSRunningApplication by a ProcessSerialNum , only by PID or bundle name. Bundle name is too ambiguous (there could be multiple instances) and I don't have the PID (it's what I want). In OSX 10.9, is there a way to get the PID when you have a PSN?

-[NSRunningApplication activateWithOptions:] not working

走远了吗. 提交于 2020-01-03 03:26:08
问题 I'm trying to create a program that will focus a certain application (if it is launched). Here is my code: #import <Cocoa/Cocoa.h> #import <stdio.h> int main() { // activate Firefox NSArray *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier: @"org.mozilla.firefox"]; if ([apps count] == 0) { printf("no matching app\n"); return 1; } if (![apps[0] activateWithOptions: NSApplicationActivateAllWindows]) { printf("failed to activate\n"); return 1; } return 0; } When I run this,

How to get the PID from a ProcessSerialNum in OSX 10.9?

和自甴很熟 提交于 2019-12-05 10:48:31
GetProcessPID was marked deprecated in OSX 10.9 along with the note: Use the processIdentifier property of the appropriate NSRunningApplication object. The problem is the constructing class methods for NSRunningApplication do not have a way to get a NSRunningApplication by a ProcessSerialNum , only by PID or bundle name. Bundle name is too ambiguous (there could be multiple instances) and I don't have the PID (it's what I want). In OSX 10.9, is there a way to get the PID when you have a PSN? Observe the NSWorkspaceDidLaunchApplicationNotification notification. In the callback, get the process

-[NSRunningApplication activateWithOptions:] not working

折月煮酒 提交于 2019-12-01 14:19:21
I'm trying to create a program that will focus a certain application (if it is launched). Here is my code: #import <Cocoa/Cocoa.h> #import <stdio.h> int main() { // activate Firefox NSArray *apps = [NSRunningApplication runningApplicationsWithBundleIdentifier: @"org.mozilla.firefox"]; if ([apps count] == 0) { printf("no matching app\n"); return 1; } if (![apps[0] activateWithOptions: NSApplicationActivateAllWindows]) { printf("failed to activate\n"); return 1; } return 0; } When I run this, it prints "failed to activate," and Firefox is not brought into focus. What am I doing wrong? Just use

NSRunningApplication, return list of recently used applications?

泪湿孤枕 提交于 2019-12-01 00:36:40
I'm trying to get a list of the most recently used applications. NSWorkspace returns a list of active applications and I can sort them on a few options using NSRunningApplication . see list below: - launchDate - finishedLaunching - processIdentifier I don't want the launch date but the most recent 'active' date (like the way cmd - tab sorts). Does anyone know the solution for this? 0xced There is no documented way of doing this that I'm aware of, but I wrote exactly what you are asking for using private APIs: http://gist.github.com/163918 Also, see Getting the list of running applications

unable to detect application running with another user (via switch user)

偶尔善良 提交于 2019-11-28 09:29:16
Use case : I login as " user1 " and launch Safari, then I click " user1 " on top-right corner and switch user to " user2 ". Now, I am trying to detect whether Safari is running for " user1 " but I am unable to do so with standard calls. I am using OS X 10.8 Mountain Lion for both development and running my code. I have used the following but in vain: [[NSWorkspace sharedWorkspace] runningApplications] - Safari not there in the list GetNextProcess() - Safari does not come up GetProcessForPID() - I get an error "no such process" But when I do a ps -aef | grep Safari from the terminal, I can see

unable to detect application running with another user (via switch user)

感情迁移 提交于 2019-11-27 02:56:05
问题 Use case : I login as " user1 " and launch Safari, then I click " user1 " on top-right corner and switch user to " user2 ". Now, I am trying to detect whether Safari is running for " user1 " but I am unable to do so with standard calls. I am using OS X 10.8 Mountain Lion for both development and running my code. I have used the following but in vain: [[NSWorkspace sharedWorkspace] runningApplications] - Safari not there in the list GetNextProcess() - Safari does not come up GetProcessForPID()