How force MacOS to ask for permissions?

Hello!
How are you guys today?

I need to allow my xojo app to execute an Apple Script. It’s not calling and i’m getting this error:

image

How can i force MacOS to ask the user, like this example:

after click Allow, it it’s authorized on System:

All help will be greatly appreciated.

Alex

See my AppleScript wrapper runAS from Xojo + Alfred (uses MBS plugin). Or have a look at the MBS plugin directly.

You need to ask for the permissions and you need a reason. Don’t forget to codesign your app. Also keep a built version of your app around or the permissions will be deleted.

Hi!

I don’t want to use any kind of plugin.

You need to ask for the permissions and you need a reason.

Where do i ask for permissions?

This app is for my use only do i need to codesign anyway?

Also keep a built version of your app around or the permissions will be deleted.

Even during the debug tests?

That’s why I said to look at the plugin at least for the plist and the reason. But I don’t know how to ask for permissions without plugin.

Yes, you need to codesign anyways or you will go bonkers when you have to give the permissions for every debug run. And also yes, even during debug tests. If there is no app then the permissions are removed.

This is my sub routine when the user clicks a check box:

//When switching this option, ask for admin password first
dim p_s1 as Shell
dim ShResult as String
dim OldValue,DotheSwitch as Boolean
OldValue=PrefsSecuremode
app.LastMethod = “PrefsWindow.PrefsSecureCheckbox.Action”p_s1= new Shell
'p_s1.Execute “osascript -e ““do shell script "“ls"”  with administrator privileges”””
'p_s1.execute “osascript -e ““tell application "“Finder.app"” to activate”””
p_s1.Execute “osascript -e ““do shell script "“echo hello"”  with administrator privileges”””
ShResult= p_s1.Result
#if DebugBuild then MessageDialog.Show "Debugbuild: " + ShResult
'if mid(p_s1.result,i,15) = “execution error” then'
//wrong password
'end if
DotheSwitch= True
if ShResult.IndexOf(“execution error”) <> -1 then
DotheSwitch= false
end if
if DotheSwitch= True then
if PrefsSecuremode= True then
PrefsSecuremode= false
'MessageDialog.Show “false”
elseif PrefsSecuremode= false then
PrefsSecuremode= True
'MessageDialog.Show “True”
end if
else
PrefsSecuremode=OldValue
end if
if PrefsSecuremode= True then
me.Value= True
elseme.Value= false
end if
p_s1.Close

This method requires a shell.

Unfortunately, the user sees “Osascript wants to make changes” when being asked for the administrator permission.

The main line listed above reads:

p_s1.Execute “osascript -e ““do shell script "“echo hello"” with administrator privileges”””

My fault!

i did wrong on Property List. i did “boolean” instead of string…

All running fine now!

May i ask: Which property, which list?
This may was the “Solution” for you, but maybe not for someone reading this thread in the future seeking for “Solution”.

2 Likes

Alex., the mistake was in your initial code, was it? could you please post your way you’ve coded it? :wink:

my mistake:

this is the correct:

1 Like

Also, for testing you can use the tccutil command to reset the state, e.g.

tccutil reset All com.mycompany.myapp

where com.mycompany.myapp is the bundle ID of your app

2 Likes

I had , because of unknown, also probs the my simple Mac XOJO app try using the camera of my MacBook Pro didn’t work.

Found in MBS doku that I need to add an .plist file (drag into XOJO editor, that’s all) which tells the app asking for access privileg dialog using camera (or not).