nsworkspace

How to migrate NSWorkspace notifications to Swift 4?

半世苍凉 提交于 2019-12-06 04:07:48
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 suggested fixes: Type 'NSNotification.Name' has no member 'NSWorkspace' How do I do this in Swift 4? To

Unmounting Drive/volume without ejecting

丶灬走出姿态 提交于 2019-12-05 04:38:17
问题 I am want to unmount a disk WITHOUT EJECTING. To do that I tried following code { NSString *path; CFStringRef *volumeName=(__bridge CFStringRef)path; DASessionRef session = DASessionCreate(kCFAllocatorDefault); CFURLRef pathRef = CFURLCreateWithString(NULL, CFSTR("/volumes/Untitled"), NULL); DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, pathRef); DADiskUnmount(disk, kDADiskUnmountOptionForce, NULL, NULL); } This code is from this question, Thanks to @zeFree Its

Unmounting Drive/volume without ejecting

与世无争的帅哥 提交于 2019-12-03 20:54:37
I am want to unmount a disk WITHOUT EJECTING. To do that I tried following code { NSString *path; CFStringRef *volumeName=(__bridge CFStringRef)path; DASessionRef session = DASessionCreate(kCFAllocatorDefault); CFURLRef pathRef = CFURLCreateWithString(NULL, CFSTR("/volumes/Untitled"), NULL); DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, pathRef); DADiskUnmount(disk, kDADiskUnmountOptionForce, NULL, NULL); } This code is from this question, Thanks to @zeFree Its working but I want dynamic path to the volume where as in the code its static. I tried changing NSString

OSX/Swift: Call function when screen becomes available

徘徊边缘 提交于 2019-12-03 12:27:15
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 this, or should I do something else entirely? Some kind of example Swift code would be really helpful

Show folder's contents in finder using Swift

一世执手 提交于 2019-12-01 03:14:11
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: dataPath) var selectedURLs = [urlPath!] NSWorkspace.sharedWorkspace().activateFileViewerSelectingURLs

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

How to get the path to the current workspace/screen's wallpaper on OSX?

倾然丶 夕夏残阳落幕 提交于 2019-12-01 00:03:56
Since AppKit version 10.7, NSWorkspace.desktopImageForScreen may return a path to a folder instead of a file's URL which is currently the wallpaper. This folder is the the place from where the wallpapers will be sequentially picked up for display. (Search for setDesktopImageURL in the release notes ). In case the user has set the desktop image to change randomly every thirty minutes or so, is there any way of determining what are the currently active wallpapers per screen in OSX? Update : Based no the answer by @l'L'l, I created a small Mac OSX app to conveniently find the currently active

How to get the path to the current workspace/screen's wallpaper on OSX?

寵の児 提交于 2019-11-30 18:38:02
问题 Since AppKit version 10.7, NSWorkspace.desktopImageForScreen may return a path to a folder instead of a file's URL which is currently the wallpaper. This folder is the the place from where the wallpapers will be sequentially picked up for display. (Search for setDesktopImageURL in the release notes). In case the user has set the desktop image to change randomly every thirty minutes or so, is there any way of determining what are the currently active wallpapers per screen in OSX? Update :

Cocoa: Sandbox entitlement to launch another application

 ̄綄美尐妖づ 提交于 2019-11-28 10:58:11
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 blocked by the "Launch Services Sandbox Daemon" (lsboxd) which doesn't think app 1 should be launching app

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