Never waiting to Sync Icloud Push your Mobile Performance

Platform

[X] iOS
[ ] Android

Obsidian Mobile version: v 1.0.5


We all love Obsidian but sometimes its anoing to wait to Sync the Icloud Files. especially if you have only Edge.

I bought a workaround on Fiverr and mabye one of you have the same problem. I want to Share it.

Here is my Guide:

  1. Download the App Scriptable.
  2. Open Scriptable, open settings and add a Bockmark Folder. Take the Obsidian Folder.
  3. Open Apple shorcuts and create an automation. Take a action to Sync your vault your preferably. I take verytime i connect to a Wi-Fi.
  4. take “run Inline script” as action.
  5. Add the script:
    let bookmarkName = “Obsidian”
    let fm = FileManager.iCloud()
    if(fm.bookmarkExists(bookmarkName)) {
    let folder = fm.bookmarkedPath(bookmarkName)
    let files = fm.listContents(folder)
    files.forEach(f)
    function f(name) {
    let filePath = fm.joinPath(folder, name)
    fm.downloadFileFromiCloud(filePath)
    }
    return (“Bookmark '” + bookmarkName + “' found\n\n” + “Files found:\n” + files)
    }else {
    return “Bookmark '” + bookmarkName + “' not found”
    }
    Script.complete()

Done!
In my case my Vault on my iphoneX and my Ipad Pro 2 or 3 :slight_smile: is a lot faster.

if you have some feedback, let me know.

Hope this make your day a little bit better.

3 Likes

Thanks for sharing!

After copy and pasting the script, it first did not work, but then I noticed that the single and double quotes in the script got mangled when the code was posted to the forum. Here is a fixed version for anyone else interested in trying this out:

let bookmarkName = "Obsidian"
let fm = FileManager.iCloud()

if(fm.bookmarkExists(bookmarkName)) {
	let folder = fm.bookmarkedPath(bookmarkName)
	let files = fm.listContents(folder)
	files.forEach(f)
	
	function f(name) {
		let filePath = fm.joinPath(folder, name)
		fm.downloadFileFromiCloud(filePath)
	}

    return ("Bookmark '" + bookmarkName + "' found\n\n" + "Files found:\n" + files)

} else {
    return "Bookmark '" + bookmarkName + "' not found"
}

Script.complete()

I just got it working, so I don’t have a sense yet, to what extent it will actually reduce/eliminate the “Waiting for iCloud to synchronize” wait times for me, but I don’t see why it wouldn’t. I’m very glad I found this thread.

For anyone else trying this out:
The script looks like it’s supposed to display either a “Bookmark ‘Obsidian’ not found” message or a list of the files that it found. Those messages are only shown, however, when you run the script from inside the Shortcuts app (i.e., by pressing the little blue “play icon” button in the bottom right while editing the Run inline script action). When the actual automation is triggered, you only get a generic “Running your automation” notification, which is preferable anyway, because the point of the script is only to trigger an iCloud sync for the Obsidian folder.

Mission accomplished! :slight_smile:

2 Likes

thanks for share.

but the script only work for the file in the folder, if my folder have child-folder, the file in child-folder won’t be download.

how to solve this?

1 Like

Scriptable app can only on mobile, how about macOS?

@einfachJens @BeR I’m not seeing the Obsidian folder in my iphone (possibly because I chose icloud to store the vault from the start in Osidian app. Am I missing something?

1 Like

As @taofuns pointed out, the original script would only download files directly inside the specified bookmarked folder, but it would not download files in subfolders.

In order to address this limitation, I rewrote the script that @einfachJens so kindly provided. Here is the new version:

//--------------------------------------
// User editable variables
//--------------------------------------
// Name of the Folder Bookmark in Scriptable:
let bookmarkName = "Obsidian"

// Return debug output (set to "true" or "false"): 
let returnDebugInfo = false
//--------------------------------------


let fm = FileManager.iCloud()
let globalLog = "Files and folders processed in bookmarked folder \"" + bookmarkName + "\":\n\n"

function processFolder(folderPath) {
	let folderContents = fm.listContents(folderPath) // returns a list of strings like ["Note1.md","aFolder"]
    for (let i=0; i<folderContents.length; i++){
        processItem(folderContents[i], folderPath)
    }	
}

function processItem(itemName, parentPath) {
    let itemPath = fm.joinPath(parentPath, itemName)
    if (fm.isDirectory(itemPath)){
        globalLog += "Folder: " + itemPath + "\n"
        processFolder(itemPath)
    }
    else {
        globalLog += "File: " + itemPath + "\n"
        fm.downloadFileFromiCloud(itemPath)        
    }
}

if (fm.bookmarkExists(bookmarkName)) {
	let bookmarkPath = fm.bookmarkedPath(bookmarkName) // this actually returns some kind of folder object like "Folder (myNotes)"	
	processFolder(bookmarkPath)
    if (returnDebugInfo) {
        return globalLog
    }
} else {
    return "Bookmark '" + bookmarkName + "' not found!"
}

Script.complete()


Here are a few notes:

  • If you, like @INymoEmE, can’t seem to find the “Obsidian” folder when you try to create a Folder Bookmark in Scriptable, it’s very likely that you are currently not in the “iCloud Drive” section of the files picker but in “On my iPhone” (or “Dropbox” or any other section that is not “iCloud Drive”). So click on the button on the top left of the file picker window until you are at the top level where you see “iCloud Drive” among the other sections.
  • The script now only returns output if either there is something wrong with the Folder Bookmark set up in Scriptable or if you set returnDebugInfo to true at the beginning of the script. I would therefore recommend that you add a “Show Result” action after the “Run Inline Script” action in the automation in Shortcuts. This way, you will get notified if for some reason the Folder Bookmark stops working (e.g., after migrating to a new iPhone), but you won’t get spammed with output windows each time the iCloud sync is automatically triggered.
  • If you looked at this automation at the beginning of 2022 when it was originally posted and decided against actually using it because iOS was very restrictive back then and required manual confirmation for many types of triggers such as “When I leave {my home address}”, I have good news for you: Things are much better now on iOS 17 and many triggers can be set up to no longer require manual confirmation each time the automation is run (see here for more details).
1 Like