can't create file or access file

Hello,

a customer of my application (MacOS X) has the following problem with a new version. The older application works fine and I doesn’t change anything of this part of the application.

When he starts my application the application try to create a file „Voreinstellungen.xml“ in the same directory where the application is. but he gets an error message that the application can’t create the file or can’t open the file.

this is my code

[code]Dim g as FolderItem

if NOT PrefsWerdenGeladen then
PrefsWerdenGeladen=true

g=GetFolderItem(PrefsDatei)
MsgBox g.AbsolutePath + " " + g.Name + " " + g.Permissions.ToText
if g<> nil and g.iswriteable and NOT g.locked then
If PrefDic.SaveXML(g, False) Then
// Saved
Else
MsgBox “Error saving XML”
End If
elseif g=nil then
//allgemeines Problem
Fehlermeldung(TextFehler003a + PrefsDatei + TextFehler003c)
elseif NOT g.iswriteable then
//Datei ist schreibgeschuetzt oder schon in Benutzung
Fehlermeldung(TextFehler003a + PrefsDatei + TextFehler003b + " (is not writable)")
elseif g.Locked then
//Datei ist schreibgeschuetzt oder schon in Benutzung
Fehlermeldung(TextFehler003a + PrefsDatei + TextFehler003b + " (locked)")
end if

PrefsWerdenGeladen=false
end if[/code]

the MsgBox is new testing Code. At the moment I have no screenshot of this. I am waiting for response from my customer.
PrefsDatei is only a string „Voreinstellungen.xml"

do you have any idea where this is coming from and how I can fix this. I have on all of my Computers nowhere this problem and the user sends me screenshots where I can see that permissions are read and write for his user to the folder and the files in this folder. When he copies the Voreinstellungen.xml file in the folder to the Application he catches the same error message but the file has also the permissions read and write for him.

thanks for ideas and help. It would be great also when you have some ideas what code I could add to make testing and finding the problem easier.

It is so difficult to find a solution, when the problem is not reproducible ob my computer.
When I get more informations/feedback I will add it to this post.

Claudius

Don’t do this. It is common for users to not have write-access to the Application folder and thus cannot write to files in it.

You should use a location designed for writing, such as SpecialFolder.ApplicationData.Child(“MyAppFolder”).

You should definitely handle this using Paul’s suggestion, but what is likely happening this that the newly downloaded application is being translocated by the OS.

When you download an application from the internet, if it is run from the same location where it was downloaded, the OS will temporarily copy the application to a read-only location and run the it from there. If the user manually moves the application in the Finder to any location other than where it was downloaded, the quarantine is removed from the application and it will run normally. It assumes that if the user takes that deliberate action, then they have knowingly downloaded the application and have authorized it to run.

You can check for this within Activity Monitor by selecting the application and then clicking the “i” button in the upper left. The “Open Files and Ports” tab will show the application accessing files within a folder path containing “/AppTranslocation/” which is the protected read-only location that the OS has created.

The best way to avoid this with applications that are distributed outside of the app store is to code sign the application, place it into a DMG, and also code sign that DMG. Then when the user mounts the DMG and copies the application, the quarantine will be automatically removed.

I have no “code sign”. I am only developing for fun. But it would be great when the software is also running without problems in all the Macs of my family or friends.

What is the best solution that the app is still possible to run without the “code sign”?

In terminal:

xattr -d com.apple.quarantine /path/to/myapplication.app

That will manually remove the quarantine from your application after it is downloaded.
Replace the path with the actual path to your .app file of course.

Or have the person who downloaded the file copy it to their applications folder, or anywhere other than the location where it was downloaded.

thanks a lot :slight_smile:

I’m sorry, I have to disagree. The best possible solution for an app to run without being code signed is:

[quote=356722:@Paul Lefebvre]Don’t do this. It is common for users to not have write-access to the Application folder and thus cannot write to files in it.

You should use a location designed for writing, such as SpecialFolder.ApplicationData.Child(“MyAppFolder”).[/quote]

Agreed, I was just providing a solution for removing the quarantine, but the application still should not be writing to its parent directory.