Where to write files on disk from my Sandbox app without User interaction? - objective-c

I have designed an app for MacOSX. Its function is to manipulate PDf files.
First the user would import files "in" the app.
After manipulating the files, the files are saved and kept in the library.
Actually, it is exactly the concept of Library of iTunes. You have files inside and you don't bother where they are located. It is better if the user do not have to select any folder in the system.
My question is : Where do I write my files on the disk?
I know I have to write it in a specific place but I can't figure out where. I tried in the App Bundle but I read somewhere we can not with sandboxing and indeed it didn't work.
I know I can write my preferences in my NSUserDefaults. Can I write any files there?

You can store the files in the application support directory. Use NSFileManager to locate it as described here: URLsForDirectory
And read the sandbox documentation for further details.

Related

NSSavePanel for Mac Catalyst?

Objective: a sandboxed application for Mac Catalyst. I need to create a file for writing data on external drive.
As far as I understand, there should be some kind of dialog which grants permission to write data to a specific location outside of the app sandbox.
What kind of dialog should I use?
Usually I followed this procedure: create a file in the app documents directory and then use [UIDocumentPickerViewController alloc] initForExportingURLs to move this file outside of the sandbox.
But now I need to create a file for writing on external drive instead (file cannot be created in documents directory because it will exceed internal storage capacity, but external drive is big enough). What "save file dialog" should be used for that?
Ok, I found the solution.
Add a plugin to the Mac Catalyst project which allows usage of AppKit functions (NSSavePanel is declared in <AppKit/NSSavePanel.h>). Detailed explanation how to add such plugin is here: https://www.highcaffeinecontent.com/blog/20190607-Beyond-the-Checkbox-with-Catalyst-and-AppKit
Create a function in that plugin which uses NSSavePanel.
Call this plugin function from main Mac Catalyst app.
Using this approach makes NSSavePanel to be displayed, and the chosen file has all necessary permissions for writing.

Making python-based .exe file accessible to anyone

I have used Spyder (Anaconda) to generate a Python GUI App. The app can browse & load any time series csv file on the user's pc, perform few statistical tests and print the results on to a txt file and save it to the user's desktop screen.
Is it possible to upload the executable file on to any repository so that others could try it out. For example, Google Earth Engine based apps can be easily shared via a link and anyone with that link can access the app. Similarly, is there anything for my case ?
This may not be the answer your looking for,
But you can upload .exe to Google drive and share it. So anyone could download it from the link generated.
File types: Users can upload any type of file, including executables
(for example, .exe or .vbs) and compressed files.
source

Tcl/tk uploading files

I'm doing a package manager for Pure Data externals in which the user may have the option to upload the created package in a repository.
Unfortunately, I was not able to find a good example from which i can develop a file uploader in tcl.
Can someone help me with an easy to understand code?
Something simple that only needs the file (given by path), url, name and password from the user.
Take a look at these Tcl Wiki pages about upload.

How to read a shortcut file (and get its target) in a Windows RT metro app?

I have accessed normal files and folders, but unable to read the target value from a shortcut file. Any idea how to read a shortcut file in WinRT?
My actual requirement is to find the most recently used/opened files in the system This info was previously available through Environment.GetFolderPath(Environment.SpecialFolder.Recent)
Thank you in advance :)
There is a file AppData\Local\recently-used.xbel which contains this information on Win8. Parsing it should be easy, but the problem will probably be to get access to this file as it isn't in the folders that can be accessed via any manifest declaration. Also the AppData folder is hidden, making it inaccessible via the FileOpenPicker.
My guess would be that this is an intentional change by Microsoft since it is no business of a sandboxed app, which documents were used by other apps. If you want to open files that were recently opened by your app, you can roll your own "recently changed" implementation. Which should be easy because you have to save their token to the FutureAccessList anyhow.

Working Directory in Objective-C and Xcode: debug mode vs. executable

I am writing a program in Objective-C using Xcode. My program creates a file as follows:
[#"" writeToFile:fileName atomically:YES encoding:NSUTF8StringEncoding error:NULL];
I would like the file to be created in the same directory as the executable. When I run the program from Xcode, the file is created in the debug directory as expected.
However, when I run the .app file, the file is created in the root directory. How can I get the program to create a file in the directory where the .app file is located.
Thanks a lot.
EDIT: This is a MacOS application
EDIT2: Well, it seems that I shouldn't be writing to the .app directory. Thanks bbum and Paul R. What is the proper way to do it? To be more concrete, here's what I am doing: each time the user clicks a button in the application, a piece of hardware connected to a serial port will send a bunch data which will be written to a new file. This can happen any number of times while the application is running, so numerous files may be created. I would like them all created in the same folder.
You must never make any assumptions about the initial working directory for your application, as this will depend on what method was used to launch it (e.g. Finder, Terminal (via open), Xcode, gdb, third party utility, etc). You should use an appropriate API to find a suitable directory to store temporary files or user-specific files or whatever it is you need to do. This should never be within the app's bundle and never at a path that is relative to the initial working directory.
You do not want the file to be created inside the .app wrapper. That is never the right answer; your application may easily be installed somewhere where the current user does not have write access to the YourApp.app wrapper.
(For example, my main user account is non-admin and all applications are installed admin-write-only. If an app ever fails to work because it can't write to its app wrapper, the app goes in the trash.)
See this question for an outline of where files should be stored. Depends on the role of the file.