0

I am new to mac os x programming. Here, is what I wanted to do.

I just wanted to access(read/write) files/images in user's desktop folder. My app is sandboxed app.

To access desktop folder, I wanted to ask for user's permissions.

The one way that I found is using NSOpenPanel but the problem is, it allows any user selected folder's access, whereas I don't want permission for any other folder, I just want to have permission for desktop folder, If user allows then should be able to access files from desktop and if user denies, then ignore given operation.

Can somebody given me solution to access/ask for permission for only single specific folder(not user selected) on mac os?

Mehul Thakkar
  • 12,440
  • 10
  • 52
  • 81
  • Frame challenge: Are you sure you want to do this? You should probably leave the desktop in the user’s control, and not write files there unless explicitly requested to, in which case the standard file dialogs will take care of permissions for you. – Ture Pålsson Apr 13 '23 at 07:24
  • Actually, I just wanted to read the images on desktop folder and process them if user allows and save the processed/edited image back to desktop folder. – Mehul Thakkar Apr 13 '23 at 07:26
  • In a sandboxed environment `NSOpenPanel` is indeed the only way, but you could check the selected folder and if it's not the desktop show the panel again and tell the user that only the desktop folder is supported. – vadian Apr 13 '23 at 07:29
  • @vadian thanks, last option in my mind is that only, but I can see many mac applications, when we install them, it shows alert that XXX applications will access your YYY folder on your mac. So, I just wanted that way. – Mehul Thakkar Apr 13 '23 at 07:32
  • Are these apps sandboxed? – Willeke Apr 13 '23 at 11:14
  • @Willeke I already mentioned that in question in second line, my app is sandboxed app. – Mehul Thakkar Apr 14 '23 at 08:18
  • Are the "many mac applications, when we install them, it shows alert that XXX applications will access your YYY folder on your mac" sandboxed apps? – Willeke Apr 14 '23 at 12:23
  • @Willeke, Not sure, but I have seen such alert, so asking. – Mehul Thakkar Apr 14 '23 at 12:37
  • I'va also seen the alert and can reproduce it but the app is not sandboxed. – Willeke Apr 14 '23 at 14:07
  • 1
    You can limit `NSOpenPanel` to the desktop folder by implementing `NSOpenSavePanelDelegate.panel(_:shouldEnable:)`. – Willeke Apr 14 '23 at 14:11

0 Answers0