1

How can I make the dock Downloads stack bounce programmatically? I don't want to bounce my app's icon.

I found this Solution for Objective-C on the Web:

[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"com.apple.DownloadFileFinished" object:pathToFile];

And changed them to a Swift-Pedant, but this doesn't work:

let defaultCenter = DistributedNotificationCenter ()    
defaultCenter.postNotificationName(NSNotification.Name(rawValue: "com.apple.DownloadFileFinished"), object: file.absoluteString, userInfo: nil, deliverImmediately: true)

I'm using Swift 5 for a Mac App and macOS Mojave 10.14.6.

In particular, I'm downloading a file from my app to Downloads folder. No problem with this, but I want the Downloads icon to bounce when the download is finished (as happen when Safari completes a download).

HangarRash
  • 7,314
  • 5
  • 5
  • 32
Aeneon
  • 29
  • 1
  • 2
    The translated code would be `DistributedNotificationCenter.default().post(name: NSNotification.Name("com.apple.DownloadFileFinished") object: file.path)`. Give that a try. – HangarRash Mar 20 '23 at 00:58
  • There's still no Error in the Log and it doesn't work. Maybe Apple has changed the NSNotificationName for this ? – Aeneon Mar 20 '23 at 01:08
  • 1
    Well the Objective-C code shown at [this answer](https://stackoverflow.com/a/8342974/20287183) is over 11 years old. macOS has changed a lot in that time. – HangarRash Mar 20 '23 at 01:10
  • Ok, small Update: I found the "com.apple.DownloadFileFinished" in Function bounceDownloadsFolderInDock() inside the Plash-App: https://github.com/sindresorhus/Plash/blob/main/Plash/Utilities.swift. Since this App is for newer Macs and running on macOS 10.15 and higher it should still be available. I found the String also in Safari.framework … – Aeneon Mar 20 '23 at 01:51
  • 1
    That code shows the same code I posted in my earlier comment. So perhaps the code is correct but the URL you are using isn’t correct. – HangarRash Mar 20 '23 at 03:42
  • I managed it to get it working by replacing a Part of the url.path with `url.path.replacingOccurrences(of: "Library/Containers//Data/", with: "")` … – Aeneon Mar 20 '23 at 07:56
  • You should post an answer below showing your complete solution. – HangarRash Mar 20 '23 at 14:54
  • It appears that "com.apple.DownloadFileFinished" only works in non-sandboxed apps. – Jonny Jul 23 '23 at 06:28

0 Answers0