nsworkspace

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

macOS: Detect all application launches including background apps?

ぐ巨炮叔叔 提交于 2020-01-14 03:56:35
问题 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: @

Cannot receive NSWorkspaceDidWakeNotification in swift OSX

梦想的初衷 提交于 2020-01-02 04:37:08
问题 I'm making a mac application where it's necessary to do something when the computer wakes falls asleep and wakes up, but I can't get the listener to work. I feel like I've tried everything. In AppDelegate.swift, inside of the function applicationDidFinishLaunching, I've got: NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self, selector: "sleepListener", name: NSWorkspaceWillSleepNotification, object: nil) NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self,

Show folder's contents in finder using Swift

自古美人都是妖i 提交于 2019-12-30 08:14:43
问题 I want to be able to select a folder and show its contents in the Finder. I have managed to select the folder itself and select a file within the folder. But I don't know how to show the contents of an empty folder. e.g. Folder A/Folder B I want to display the contents of folder Folder B (which could be empty). I have written the following code: func showFolder(fileName : String) { var dataPath = homeDirectory.stringByAppendingPathComponent(fileName) var urlPath = NSURL(fileURLWithPath:

Show folder's contents in finder using Swift

一个人想着一个人 提交于 2019-12-30 08:14:27
问题 I want to be able to select a folder and show its contents in the Finder. I have managed to select the folder itself and select a file within the folder. But I don't know how to show the contents of an empty folder. e.g. Folder A/Folder B I want to display the contents of folder Folder B (which could be empty). I have written the following code: func showFolder(fileName : String) { var dataPath = homeDirectory.stringByAppendingPathComponent(fileName) var urlPath = NSURL(fileURLWithPath:

NSWorkspace's 'frontmostApplication' doesn't change after initial use

拜拜、爱过 提交于 2019-12-25 06:33:06
问题 I'm trying to get an update of the current active (foreground) application. Even across computer screens. I'm using this code to try to do it: print(NSWorkspace.sharedWorkspace().frontmostApplication?.localizedName) This loops in a command line application every 3 seconds, and prints to console. It works with any application open as active when it first starts up. However, it does not change from the first app afterwards. 1. Why is it doing this? 2. What is the proper code to make it work? 3.

How to send and receive NSAppleEventDescriptor when using NSWorkspace to open URLs between apps?

放肆的年华 提交于 2019-12-24 07:29:14
问题 NSWorkspace has the method open(_:withAppBundleIdentifier: [...] ) : Opens one or more files from an array of URLs. func open(_ urls: [URL], withAppBundleIdentifier bundleIdentifier: String?, options: NSWorkspace.LaunchOptions = [], additionalEventParamDescriptor descriptor: NSAppleEventDescriptor?, launchIdentifiers identifiers:) -> Bool The NSApplicationDelegate of the app you want to open has corresponding methods that are called to open the URL(s) you provide: func application(_ sender:

How to send and receive NSAppleEventDescriptor when using NSWorkspace to open URLs between apps?

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:29:12
问题 NSWorkspace has the method open(_:withAppBundleIdentifier: [...] ) : Opens one or more files from an array of URLs. func open(_ urls: [URL], withAppBundleIdentifier bundleIdentifier: String?, options: NSWorkspace.LaunchOptions = [], additionalEventParamDescriptor descriptor: NSAppleEventDescriptor?, launchIdentifiers identifiers:) -> Bool The NSApplicationDelegate of the app you want to open has corresponding methods that are called to open the URL(s) you provide: func application(_ sender:

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

喜欢而已 提交于 2019-12-23 03:58:13
问题 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

How to migrate NSWorkspace notifications to Swift 4?

佐手、 提交于 2019-12-22 15:25:53
问题 In Swift 3 I registered for sleep and wake notifications with this code: let notificationCenter = NSWorkspace.shared.notificationCenter notificationCenter.addObserver(self, selector: #selector(AppDelegate.sleepListener), name: NSNotification.Name.NSWorkspaceWillSleep, object: nil) notificationCenter.addObserver(self, selector: #selector(AppDelegate.wakeUpListener), name: NSNotification.Name.NSWorkspaceDidWake, object: nil) but after migrating to Swift 4, I get this error after applying the