Tuesday, January 28, 2020

#1 2020-01-08 04:52:18 pm

bentoms
Member
Registered: 2008-10-21
Posts: 79
Website

Catalina - prompting for access to protected dirs

Hi folks,

How does one go about prompting for access to protected directories in Catalina within a AppleScriptObjC app?

For example:

Screenshot%202020-01-08%2022.14.14.png?raw=1

Last edited by bentoms (2020-01-08 04:53:44 pm)

Offline

 

#2 2020-01-08 05:21:39 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6151

Re: Catalina - prompting for access to protected dirs

You don't -- the system does it when you try to read something in one.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2020-01-08 05:25:14 pm

bentoms
Member
Registered: 2008-10-21
Posts: 79
Website

Re: Catalina - prompting for access to protected dirs

Shane Stanley wrote:

You don't -- the system does it when you try to read something in one.



Thanks, Shane.

I’m not getting a prompt.

For my app, folks drag an item onto it.. I then copy that item via 'cp'

It’s this do shell 'cp' that’s getting operation not permitted, even moved to NSFileManager & no prompts.

My next test was to revert to an open file panel.

Offline

 

#4 2020-01-08 05:32:19 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6151

Re: Catalina - prompting for access to protected dirs

It sounds like you don't have the relevant purpose string entry in your app's Info.plist file. And don't use cp.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2020-01-08 06:01:30 pm

bentoms
Member
Registered: 2008-10-21
Posts: 79
Website

Re: Catalina - prompting for access to protected dirs

Already added NSFileManager instead of cp.. but the purpose string.

If I add sandbox to the apps capabilities then check of the options, still same error.

Got any examples here incase I’m holding it wrong?

Offline

 

#6 2020-01-08 06:14:34 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6151

Re: Catalina - prompting for access to protected dirs

You don't want sandboxing. Do you have an entry for NSDesktopFolderUsageDescription/Privacy - Desktop Folder Usage Description in your Info.plist?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#7 2020-01-08 10:55:21 pm

technomorph
Member
Registered: 2017-12-14
Posts: 130

Re: Catalina - prompting for access to protected dirs

What’s the settings I should have in my entitlements or plait for
Shell  accesss.   (On 10.11)

I spend days trying to figure it out.
Googling etc.

When I turned sandboxing off it worked.

I had to turn sandboxing on to get access to my music folder
For ITLibrary framework use.

Can I just copy the entry from my entitlements  file and place that in
My info.plist?

Offline

 

#8 2020-01-08 11:01:27 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6151

Re: Catalina - prompting for access to protected dirs

technomorph wrote:

What’s the settings I should have in my entitlements or plait for
Shell  accesss.   (On 10.11)



There's no such entitlement. Using do shell script is just launching tasks. What you can do like that is still a bit fuzzy, and depends on the tool you use. Third-party tools should be notarized (apparently not a straight-forward thing to do to them).

I had to turn sandboxing on to get access to my music folder
For ITLibrary framework use.



If you're sandboxed, I suspect you can't do much with the shell -- you won't be able to pass security scoped URLs, which is how you get entitlements. 

Can I just copy the entry from my entitlements  file and place that in
My info.plist?



No.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#9 2020-01-09 02:34:20 am

technomorph
Member
Registered: 2017-12-14
Posts: 130

Re: Catalina - prompting for access to protected dirs

Thanks.   Yeah I’m
Not calling them from AppleScript but from a NSTask

It is a 3rd party python script.
I have found some stuff about notarizing them
I may try that.

The whole sandboxing thing is definitely pain in the but.

What are the downsides of turning it off?
I don’t plan to release my app in the store.
(Not Yet)

Thanks

Offline

 

#10 2020-01-09 04:00:44 am

bentoms
Member
Registered: 2008-10-21
Posts: 79
Website

Re: Catalina - prompting for access to protected dirs

Shane Stanley wrote:

You don't want sandboxing. Do you have an entry for NSDesktopFolderUsageDescription/Privacy - Desktop Folder Usage Description in your Info.plist?



Hi Shane,

I've added:

	NSDesktopFolderUsageDescription
	Needed for pkgcreator to copy items form you Desktop

Still no prompt, I can read files on the Desktop but not copy.

CP or NSFileManager's copyItemAtPath are failing.

This is an app which the item is dragged into, so I think i'll need to try prompting for the file: https://developer.apple.com/library/arc … older.html

Offline

 

#11 2020-01-09 05:37:56 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6151

Re: Catalina - prompting for access to protected dirs

technomorph wrote:

What are the downsides of turning it off?



Getting in the app Store is the only thing I know you need it for.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#12 2020-01-09 05:40:21 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6151

Re: Catalina - prompting for access to protected dirs

bentoms wrote:

This is an app which the item is dragged into



Then use the URL you get, not paths. So copyItemAtURL:, not copyItemAtPath:.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#13 2020-01-09 11:55:27 am

bentoms
Member
Registered: 2008-10-21
Posts: 79
Website

Re: Catalina - prompting for access to protected dirs

Shane Stanley wrote:

Then use the URL you get, not paths. So copyItemAtURL:, not copyItemAtPath:.



No difference.

I'm using the following for the drag and drop, if makes any difference: https://macscripter.net/viewtopic.php?p … 38#p165338

Offline

 

#14 2020-01-09 02:07:07 pm

bentoms
Member
Registered: 2008-10-21
Posts: 79
Website

Re: Catalina - prompting for access to protected dirs

Ok, so in a new project this works:

Applescript:

on applicationWillFinishLaunching_(aNotification)
       -- Insert code here to initialize your application before any files are opened
set theDocument to choose file with prompt "Please select a document to process:"
log theDocument
set posixDocument to POSIX path of theDocument
log posixDocument
do shell script "cp " & quoted form of posixDocument & " ~/Downloads/file2.jpg"
end applicationWillFinishLaunching_

Screenshot%202020-01-09%2020.03.05.png?raw=1

So.. maybe something with this: https://macscripter.net/viewtopic.php?p … 38#p165338

Last edited by bentoms (2020-01-09 02:07:46 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)