Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Save to arbitrary iCloud Drive path in new Pythonista?
-
The path is:
/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents
-
@omz you should perhaps modify File Picker to support local and iCloud files.
-
@JonB said:
The path is:
/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents
@JonB I wasn't talking about Pythonista docs, but rather other iCloud Drive folders. I assumed we'd now have access via path. For example:
os.listdir('/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents')
will work, but:
os.listdir('/private/var/mobile/Library/Mobile Documents/Desktop')
will not. It seems to only allow access inside the app's folder. I assumed with iOS11 and Files.app, we could have access to a path on iCloud drive.
-
@dueyfinster You're right, I've tested with File Browser which has an iCloud Drive folder.
It's strange because in the Files app, you can duplicate a file from another folder to this FB folder... -
I would advise you to not to do it. All iCloud files / documents should be modified with NSFileCoordinator only. More info in the iCloud File Management. Quote:
At the heart of the iCloud locking mechanism are file coordinators and file presenters. Whenever you need to read and write a file, you do so using a file coordinator, which is an instance of the NSFileCoordinator class. The job of a file coordinator is to coordinate the reads and writes performed by your app and the sync daemon on the same document. For example, your app and the daemon may both read the document at the same time but only one may write to the file at any single time. Also, if one process is reading the document, the other process is prevented from writing to the document until the reader is finished.
If you lose something, get weird file content, you know why :)
-
@zrzka Thanks a lot, I didn't know that, but really, what do I know? đŸ˜
-
@zrzka In my experience, naively writing files in the iCloud container mostly works fine, if you make sure that you're the only one writing (e.g. when you have a script that produces time-stamped files). In short, if you make sure that conflicts are unlikely to arise, you're probably fine, but no guarantees.
-
@omz same here, but no one never knows. It's better for others to know that smth bad can happen.
-
Hey,
icloud_path="/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/" quotes_file_name="my_quotes.txt"; #Sync to iCloud; copyfile(icloud_path+quotes_file_name, current_path+quotes_file_name);
Example code works from Pythonista IDE, but script has no access from widget.
Maybe someone can direct me to some source making it right ? Or not possible to do it ?Thanks
-
@surg30n Sorry, I don't understand. Do you want to execute this little script from the iOS widget screen? If yes, how do tout want to start the process? Without ui, button...?
-
@cvp no.. script a bit bigger. I write my own quotes to quote-file, separately. Script just gets random one and prints it. So it does it in a widget too as a console output (I added that script to widget).
Just, if script tries get the random line from the quotes-file residing in icloud, it succeeds when I run it from IDE but fails when it runs in widget. ‘Access denied’. (BTW script in widget runs itself every time when i open widgets screen or when it on left side in IOS13 always-on).
This small example here is just to show, how, f.e. Script copies quote-file from local storage to icloud. It works from IDE but fails when running in widget. Just gives out ‘access denied’ referring to icloud
-
@surg30n I think that your script copies FROM iCloud, not TO iCloud, thus are you sure the file already exists in iCloud
-
@cvp yes. It copies as in example above.
File exists in cloud for sure. -
@surg30n Sorry. You're right. Same error while trying to copy a file from Pythonista iCloud.
Not sure it has ever worked in a widget or if it is since iOS 13 and/or Pythonista beta.
You know that widget process is very limited. -
@cvp Thanks for approvement. Thought, maybe there is some appropriate method to copy file from cloud, and simple copy is not allowed in widget from the security pose, but it seems not.
-
@surg30n I've tested, with the Pythonista beta, a Siri shortcut performing only this shutil.copyfile, and I get the same error.