I have a Finder Sync Extension (FSE) which shows statuses of files. Is there a way I can force FSE to again request statuses for all files/folder currently visible in Finder window.
-
Who do you want to force? `Finder` to request statuses from your extension (`appex`) or your extension from your application? Because the second question is a matter of your internal organization (`CFMessagePort` is a solution). – Liviu Nov 24 '17 at 20:52
-
I'd like Finder to refresh statuses of all visible files and folders. Afaik, you can't do that, BUT what I can do (described in the answer) is track observed paths and cache statuses for every file Finder requested. Then, when FSE gets message from main app to refresh everything, FSE would simply iterate through all cached paths still being observed and request status for each path from the app. Additionally, FSE would delete it's internal {path->status} cache (thing is that FSE keeps cached statuses to reduce communication between FSE and Main App since I'm using distributed notifications). – mixtly87 Nov 25 '17 at 22:41
-
"Then, when FSE gets message from main app to refresh everything, FSE would simply iterate through all cached paths still being observed and request status for each path from the app." You said message from the app, but how FSE can refresh Finder when this message is received? – Liviu Nov 27 '17 at 10:09
-
FSE can invoke `[[FIFinderSyncController defaultController] setBadgeIdentifier:syncStatus forURL:url]` and thus instruct Finder to update sync icon for given URL. – mixtly87 Nov 27 '17 at 22:02
-
thank you so much, this seems to be the answer to your question ... Could you please add it to your answer to upvote you? BTW, does this always work for you? Exemple: High Sierra, copy folder with Finder - it does not always work for the new folder! – Liviu Nov 28 '17 at 11:22
-
I added the explanation. So far, this worked fine for me. I didn't notice that folder copying in Finder causes issues, I'll pay attention in the future to see if that's the case. So far, it's been working ok for me. – mixtly87 Nov 29 '17 at 10:19
1 Answers
Finder Sync Extension (FSE) has callbacks beginObservingDirectoryAtURL
and endObservingDirectoryAtURL
where you can keep track of what paths are being observed (ie by adding/removing paths to NSMutableSet
).
Also, whenever Main app informs FSE about file sync status update, FSE can cache the received state in dictionary where file path is mapped to file sync status.
Then, when FSE receives a message from the main app to refresh all items, FSE should check what paths are being observed, and then request new statuses from the main app for all cached paths having prefix in observing-set. Additionally, FSE should delete it's internal cache forcing it to request newly observed files from the main app (ie when user opens some other folder).
Once FSE receives the message from the main app, it can invoke the
[[FIFinderSyncController defaultController] setBadgeIdentifier:syncStatus forURL:url]
and thus set the proper sync status icon for the URL.
This solution assumes bidirectional communication channel between FSE and Main app which can be achieved either by using NSDistributedNotificationCenter
or via CFMessagePort
.
Also keep in mind that there can be more than one FSE instance running (ie Save dialog from 3rd app)

- 1,675
- 15
- 32
-
I'm wondering if there is a way to force finder to refresh its current view from finder extension (or any mechanism). Basically, I have a mount point with remote data source and the way I refresh finder when there is new file added in remote in a directory is to replay that filesystem operation so that finder will refresh. Not sure if there is any other ways. – yijiem Aug 09 '19 at 23:34
-
1@yijiem Hm, yes I do it in similar way. I also use `NSWorkspace. noteFileSystemChanged(path)` for this but that doesn't seem to work in latest macOS Catalina. Benjamin Fleischer suggests using `GMUserFileSystem.invalidateItemAtPath` – mixtly87 Aug 15 '19 at 07:42