I’m trying to update some handlers to work with Sonoma’s iCloud implementation. These determine the iCloud status, force download, make online-only etc.
Previously, online-only iCloud filenames were modified, prefixed with a period and suffixed with “.iCloud”. In Sonoma, and I am hoping also in Sequoia, the filenames are not munged. Now the terminal reports a file size of 0 for online files even though the “info for” window still shows the original file size.
I can use this info to update my code that determines the iCloud status of files, but I wonder if anyone knows if there are asobjc methods for brctl download, brctl evict, and maybe a method for accessing the “iCloud Status” of a file. This info is available to the Finder to display, but I don’t know any way to access it.
The NSFileManager class has the relevant methods for managing iCloud files, including:
evictUbiquitousItemAtURL:error:
startDownloadingUbiquitousItemAtURL:error:
isUbiquitousItemAtURL:
and others. I dont have Sequoia, but there’s nothing in the Apple developer documentation to suggest that these methods aren’t still available and working for all macOS systems from version 10.7 through to current.
set {evictSucceeded, theError} to (current application's NSFileManager's |defaultManager|()'s evictUbiquitousItemAtURL:theSourceURL |error|:(reference))
set {evictSucceeded, theError} to (current application's NSFileManager's |defaultManager|()'s startDownloadingUbiquitousItemAtURL:theSourceURL |error|:(reference))
But the third, checking the iCloud Status, I’m messing up the call.
set theSourceURL to my FileSystem_Object_As_NSURL(FileSystemObject)
set evictSucceeded to (current application's NSFileManager's |defaultManager|()'s isUbiquitousItemAtURL:theSourceURL)
I only get true back from this regardless of the status.
EDIT1: This apparently only indicates that a file is targeted for storage in iCloud.
These other methods are exactly what I was looking for to avoid shell scripts for upload and download!
EDIT2: Ah! Looks like “NSURLUbiquitousItemIsUploadedKey” returns a file’s upload status, but I don’t know if that indicates local or online-only, or just “has it been uploaded yet”. I may have to stick with querying the blocks used on disk value from terminal to determine that.
Under Sonoma iCloud files gained a status icon which indicates iCloud only, downloading, uploading, and local ( no icon ). I’m looking for the source of that data.
Currently I am checking the blocks-used-on-disk from the terminal to determine if a file is online-only ( 0k ) or not. EDIT: That should have read ( 0 Kb ). It reads like “OK” which is very confusing.
Again, I may be completely dense, but these terms stilll seem vague. Are we talking about whether a file is in sync ?
If so, then this sort of information about a file is stored in the file’s resource fork, or whatever the modern equivalent of this is. There’s a ton of NSURL so-called resource keys that allow you to access this information using getResourceValue:forKey:error: (for retrieval of a single resource value) or resourceValuesForKeys:error: (for retrieving multiple resource keys as a record in one go).
Collectively, these resource keys are categorised under the NSURLResourceKey type, and that link leads to the page that lists (almost) all of available keys.
However, some of the specific ones that I think are what you are referring to are:
This gives a true or false indication of whether or not downloading is in progress, but the NSURLUbiquitousItemDownloadingStatusKey provides more granular information including:
Some of them arent named at all intuitively, but have a look at these keys plus the other ones on the NSURLResourceKey page that have the word “ubiquitous” in their name (not intuitive, but, I suppose in some sense, a local file that is available in the cloud could be said to be available “everywhere”, and therefore ubiquitous, but it’s definitely a notion that requires more than one step to arrive at the connection).
Let me (or the forum, in general) know If you need some help to implement the getResourceValue:forKey:error: or resourceValuesForKeys:error: methods. The former of the two, which is for retrieving a single resource key’s value but takes three parameters compared to the latter, which is for retrieving a bunch of these resource keys’ values all at once but only requires two parameters, threw me a little at first. Again, not overly intuitive, but it’s because getResourceValue:forKey:error: usually takes a pointer to a declared variable in C that receives the value, while the method itself returns a success/failure boolean value.
I’m referring to the status of iCloud files when using “Optimize Mac Storage”. Apologies, I didn’t say that clearly anywhere.
This setting allows iCloud to make some files in your local iCloud Drive data-less.
With this setting enabled iCloud will store the entire contents of your iCloud Drive locally on the hard drive if you have enough space but If there isn’t enough space for your entire iCloud then older documents are represented in the finder but the files have no data. These files have all the icon, metadata, extended attributes, permissions etc. but not the data. Also, via contextual menu you can manually force a file to “download now” or “remove download”.
Programmatically determining if a file is an ordinary file, or a data-less file is not straightforward and changed with Sonoma. There was some drama. This status is what I was referring to as “local” or “iCloud only” which I pinched from “online-only” which, apologies, is Dropbox’s terminology for the same concept. EDIT: It looks like I almost consistently pinched the Dropbox term. I’m not surprised, I’ve used that service a long time.
It looks like you’ve given me everything that I was hoping for and revealed even more I should be aware of! I’ll give this a go and see how I get on. Thanks!
It would be nice if you could correct this Link - while it is a valid item of the Apple Developer Documentation, your link is incorrect and leads to a page not found error.
Here the source of the quote showing additional characters in the link:
[quote="CJK, post:7, topic:76358"]
the [`NSURLUbiquitousItemDownloadingStatusKey`](https://developer.apple.com/documentaDrtion/foundation/nsurlubiquitousitemdownloadingstatuskey?language=objc) provides more granular information
[/quote]