Is there a sandbox permissible way to check for presence of a folder?

Hi,

I have an app that uses alias as a way to check for presence of a folder in Application Support:
Definition of path:
tell application “System Events”
set pathDriverFolder to path of (path to application support folder)
end tell

Testing of presence of folder:
set fullPath to pathDriverFolder & “Folder”
try
fullPath as alias – throws an error if folder doesn’t exist
–log “folder exists”

            on error
            --log "folder does not exist"

end try

That works fine but I gave it temporary entitlement for system events and the app got rejected (sort of understandably)

Is there a way to check for the presence of a folder that would be accepted by the App Store?

Thanks for your help,
Uwe

Have you tried the file manager? Something like:

NSFileManager's defaultManager()'s fileExistsAtPath:posixPath

Brilliant - I keep forgetting my iOS derived knowledge, when I work with AppleScript - cheers Shane!

Now, I realise I used System Events also to modify a plist file that I created in the container. Guess I will have to use NSUserDefaults in the Sandbox ?

Best,
Uwe

Use NSPropertyListSerialization.

Thanks again Shane! Works like a charm :). I created an NSMutableDictionary and all is (seems) well. I think I should buy your book, if it is still available. Looks like I am asking obvious questions.
Now fingers crossed for the 2nd App Review ;-).

cheers,
Uwe

Update: …it is approved :slight_smile: . Thanks again, Shane!

Oh noooooo

Somehow the app stopped writing to the plist file now.

I have the plist file in my app container.

I can read the plist file fine. I actually could also write to the file yesterday, I tested it many times in Xcode and the exported app.

As mentioned above, I submitted and it got approved but users came back, stating that no data were saved.
I checked in Xcode and now it does not save there either.

I am puzzled. I thought there is no requirement for an entitlement, if you write into the app container (and also cannot find one mentioned in the Apple guidance documents).

Update: ok - it seems to be a Sandbox issue, my code is fine. Sandbox off - I can write. Sandbox on - I can’t. I am searching now for the entitlement for the container to write in there - really odd. Apple doc says, access to the app container is not regulated.User-selected file access entitlement does not work - and also should not work as it is for open panel type file access.

Update 2: To whom it concerns …
Turns out that my definition of ‘container’ may not be what Apple’s definition is:
So in Sandbox, I could not write to the ‘Resources’ of the app, which I would call a container - but I could read. So I left the starting plist there.
Then I created a path to the (most likely Apple) container of the app and checked for file presence upon start and if not present read out from the Resources file and wrote a first plist to that container (application support folder). And from then onwards only read plist from there.
All good in Xcode. Fingers crossed it will be good in life environment too.