Sonoma iCloud status, force download, make online-only

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.

1 Like

Much appreciated! I’m off to try these…

So the first two of these methods I can work out…

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.

Could anyone help me structure a valid calls to URLForPublishingUbiquitousItemAtURL?

I’m not clear on what information you specifically want. You did mention “iCloud status”, but what does that mean ?

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.

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:

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.