nsworkspace

OSX/Swift: Call function when screen becomes available

孤者浪人 提交于 2019-12-21 04:09:09
问题 I want my OSX app to call a function when the user's screen becomes available, ex: their computer wakes from sleep or the user turns on their screen. Basically any time the user goes from having no screen active to having one active, I would like my function to be called. I'm not sure if the best way to do this is to: Check for changes in sleep/wake state or Use CGDisplayReconfigurationCallback or Listen for a NSWorkspaceScreensDidWakeNotification Which of these seems like the best way to do

Open an application from another (iOS)

偶尔善良 提交于 2019-12-20 02:32:37
问题 I read that there is nothing like NSWorkspace for iOS Equivalent of NSWorkspace for iOS Unfortunately, I wanted a button in my app that can run some others applications (in background). Is it possible without NSWorkspace ? 回答1: Your first problem is that you can't run applications in the background in the same way that you can on the Mac. But, assuming that just launching an app is enough, the answer is: it depends. The other app would need a URL scheme defined. Not all do, unfortunately.

Cocoa: Sandbox entitlement to launch another application

我只是一个虾纸丫 提交于 2019-12-17 19:48:28
问题 I'm calling [[NSWorkspace sharedWorkspace] launchApplication:path]; From my sandboxed app, and I'm getting this error in the console: 9/5/11 12:23:12.462 PM lsboxd: refusing to spawn < PATH REDACTED > for 21383 - reason -10826 9/5/11 12:23:12.463 PM App: spawn_via_launchd() failed, errno=54 label=[0x0-0x1994993].MYApp path=< PATH REDACTED > flags=0 9/5/11 12:23:12.464 PM App: LSOpenFromURLSpec() returned -10810 for application < PATH REDACTED > (null). In other words, I'm clearly getting

macOS - Impossible to launch an app with localized name and space

孤人 提交于 2019-12-13 04:04:33
问题 I have this macOS app that is launched at login. This app has a space in the name "My App.app". For that matter, I have created a helper app that loads at login and launches the main app. I am inside this helper, trying to launch the main app. For this reason I need to get the main app path. So, I do: let appName = "My App.app" let path = "/Applications/" + appName let newURL = NSURL.fileURL(withPath: path) when I try to use this let app = try NSWorkspace.shared.launchApplication(at: newURL,

Cocoa Unmounting drive but not ejecting it

和自甴很熟 提交于 2019-12-12 18:04:13
问题 Do you know you to unmount a drive without ejecting it. NSWorkspace has some methods to unmount drives but it also eject them. Any idea ? 回答1: I am doing it as follows and it un-mounts the drive but doesn't eject it. (Actually I want to eject the disk, I can only un-mount the disk. :P Please share how to eject a disk.) DASessionRef session = DASessionCreate(kCFAllocatorDefault); CFURLRef path = CFURLCreateWithString(NULL, CFSTR("<path_to_your_volume_here>"), NULL); DADiskRef disk =

NSWorkspaceWillPowerOffNotification never called

前提是你 提交于 2019-12-12 11:30:13
问题 I am trying to run a program in a background process that will register every shutdown event in the system. Doing so by registering to NSWorkspaceWillPowerOffNotification as show below: #import <AppKit/AppKit.h> @interface ShutDownHandler : NSObject <NSApplicationDelegate> - (void)computerWillShutDownNotification:(NSNotification *)notification; @end int main(int argc, char* argv[]) { NSNotificationCenter *notCenter; notCenter = [[NSWorkspace sharedWorkspace] notificationCenter];

How can we add attachment to default mail Application Using NSWorkSpace in cocoa Mac OSX application

不打扰是莪最后的温柔 提交于 2019-12-10 19:06:25
问题 I am using NSWorkspace to set TO, CC, BCC , SUBJECT and body text in default mail application through my application. How can i add attachments using NSWrokSpace? Is there any way to attach files in the default mail app using NSWorkSpace? I have tried using NSSharingService but problem with NSSharingService is that you cannot set CC and BCC email addresses in the default application Email Compose. Is there any way to add CC, and BCC recipients using NSSharingSerivce ?? or is there any way to

How to force kill another application in cocoa Mac OS X 10.5

我的梦境 提交于 2019-12-08 08:04:37
问题 I've this task, from my application i need to kill another my application, the problem is that the other application has a Termination Confirm Dialog (there is no critical data to save, only confirmation of user intent to quit). On 10.6+ you will use: bool TerminatedAtLeastOne = false; // For OS X >= 10.6 NSWorkspace has the nifty runningApplications-method. if ([NSRunningApplication respondsToSelector:@selector(runningApplicationsWithBundleIdentifier:)]) { for (NSRunningApplication *app in

How to check whether directories with a given extension are shown by the Finder as a package?

泄露秘密 提交于 2019-12-06 23:48:35
For a given extension, how do you check whether directories with that extension will be shown by the Finder as a package? I figured the method below is an effective implementation for this, but creating a temporary directory feels like a hack. I'm guessing I should be able to implement this properly through the Launch Services API , but I can't quite figure out how to do it (I might be overlooking the obvious though). // Extension method on NSWorkspace @implementation NSWorkspace (MyExtraMethods) - (BOOL) isPackageExtension: (NSString*) extension { NSString * pathToTemp = [NSTemporaryDirectory

macOS: Detect all application launches including background apps?

邮差的信 提交于 2019-12-06 18:14:27
Newbie here. I'm trying to create a small listener for application launches, and I already have this: // almon.m #import <Cocoa/Cocoa.h> #import <stdio.h> #include <signal.h> @interface almon: NSObject {} -(id) init; -(void) launchedApp: (NSNotification*) notification; @end @implementation almon -(id) init { NSNotificationCenter * notify = [[NSWorkspace sharedWorkspace] notificationCenter]; [notify addObserver: self selector: @selector(launchedApp:) name: @"NSWorkspaceWillLaunchApplicationNotification" object: nil ]; fprintf(stderr,"Listening...\n"); [[NSRunLoop currentRunLoop] run]; fprintf