Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
I have Applescript which executes bash shell script using administrator privileges.

Script example: do shell script "/users/user/documents/install.sh" with administrator privileges

In Catalina, i always get an execution error - operation not permitted (126) message - bash script is not executed. Even if bash script is empty, error is the same, so i assume bash script is not the problem. Tried to do it as root - no success.

If i remove with administrator privileges, script is executed, but that's not a solution because i need to run it with privileges.

In previous macOS versions the same script is working without problems.

Any ideas? Thx in advance!!!
 
Last edited:
  • Like
Reactions: danallen

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,767
Try do shell script "sudo /users/user/documents/install.sh" with administrator privileges
 

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
Bash is no longer part of macOS with Catalina. You have to use zsh.

Hm, i have bash here and it executes"install.sh" script perfectly in terminal (without Applescript)

sudo ./install.sh

Running applescript using osascript command in terminal, results in the same error.
[doublepost=1568403803][/doublepost]Nevertheless, if i use zsh, script result is following (terminal, using osascript)

Mac Documents % osascript install.applescript
install.applescript:0:97: execution error: /bin/zsh: can't open input file: /Users/user/Documents/install.sh (127)

Needless to say that script install.sh is present and accessable in documents folder.
 
Last edited:

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,767
Try do shell script "bash /users/user/documents/install.sh" with administrator privileges
Catalina has some weird permissions bugs.
 

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
Try do shell script "bash /users/user/documents/install.sh" with administrator privileges
Catalina has some weird permissions bugs.

Thx for help!

I tried this already with no success. No matter what i do, if i use "administrator privileges", script fails. There is something which blocks applescript from executing script in admin mode.
 

alanrb

Cancelled
Jul 23, 2019
14
0
I thought Bash was still available and can be made the default shell if you prefer it. Similarly zsh is available in Mojave but Bash is the default.
 

TriBruin

macrumors 6502
Jul 28, 2008
449
951
Bash is no longer part of macOS with Catalina. You have to use zsh.
Incorrect. Bash is still included with Catalina, but is no longer the default shell when you launch terminal, ZSH is. You can still call bash scripts by using #!/bin/bash at the top of your script.

As far as the OP's script not running, it likely has to do with macOS privacy controls. I don't have a Catalina machine in front of me, but check Security & Privacy for any thing about Automation.
[doublepost=1568490502][/doublepost]
Hm, i have bash here and it executes"install.sh" script perfectly in terminal (without Applescript)

sudo ./install.sh

Running applescript using osascript command in terminal, results in the same error.
[doublepost=1568403803][/doublepost]Nevertheless, if i use zsh, script result is following (terminal, using osascript)

Mac Documents % osascript install.applescript
install.applescript:0:97: execution error: /bin/zsh: can't open input file: /Users/user/Documents/install.sh (127)

Needless to say that script install.sh is present and accessable in documents folder.
Check and make sure "Terminal" has Full Disk Access in Privacy tab of Security & Privacy. That may fix your problem.
 

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
As far as the OP's script not running, it likely has to do with macOS privacy controls. I don't have a Catalina machine in front of me, but check Security & Privacy for any thing about Automation.
[doublepost=1568490502][/doublepost]
Check and make sure "Terminal" has Full Disk Access in Privacy tab of Security & Privacy. That may fix your problem.

I already have set Full Disk Access for Terminal. Privacy Automation settings window is empty, not sure what can i do with it.

Thx!!!
[doublepost=1568495780][/doublepost]
One more thing chmod +x /Users/user/Documents/install.sh

Attributes of the bash script are correct, because script is executed properly as standalone (sudo ./install.sh). Seems that the problem is with Applescipt not being able to execute bash script with admin privileges.

I even signed bash script, still no success. It doesn't work in root mode either. It feels like permissions issue, but I still wonder if this is actually Catalina beta bug ... not sure how to check if it's maybe already reported.
 
Last edited:

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,767
Seems that the problem is with Applescipt not being able to execute bash script with admin privileges.
I wouldn't say that, my beta enrollment script works in Catalina beta 8.
I've tried to run disable.sh form AppleScript and I got an error "/bin/sh: /Users/admin/Documents/disable.sh: Permission denied" number 126
But it run after adding bash or after chmod +x. Full disk access was not required.
 

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
I wouldn't say that, my beta enrollment script works in Catalina beta 8.
I've tried to run disable.sh form AppleScript and I got an error "/bin/sh: /Users/admin/Documents/disable.sh: Permission denied" number 126
But it run after adding bash or after chmod +x. Full disk access was not required.

Unfortunately, these suggestions are not working for me (i have beta 7, though). My bash script has execution permisson set (chmod +x) - otherwise it wouldn't run as standalone as well. Anyway, i tried to set it few times, just in case :)
 

adrianlondon

macrumors 603
Nov 28, 2013
5,043
7,628
Switzerland
I don't have your issue, but a different one. An Applescript I have that sets calendar alerts depending on various bits of into in the event was working fine in Mojave, but is failing now. My Feedback says "more than 10" people have reported the same issue, so there does seem to be at least one issue with Applescript in Catalina.
 
  • Like
Reactions: zabukowski

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
Unfortunately, the problem on beta 8 remains the same.

The problem narrows down to applescript not being able to execute shell script with admin privileges (operation not permitted, can't open input file etc.) regardless of shell type (bash, zsh etc.).
 

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,767
Unfortunately, the problem on beta 8 remains the same.
The problem narrows down to applescript not being able to execute shell script with admin privileges (operation not permitted, can't open input file etc.) regardless of shell type (bash, zsh etc.).
I think I finally understood the problem: the script tries to run in /, so permission is actually denied to the root directory.
Disable SIP, mount system as writable "sudo mount -wu /" and try the script again.
 

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
I think I finally understood the problem: the script tries to run in /, so permission is actually denied to the root directory.
Disable SIP, mount system as writable "sudo mount -wu /" and try the script again.

Hm, interesting ... but isn't disabling SIP just because of ordinary applescript a bit overkill !? Maybe there is a way to change script startup directory? How did you came to conclusion that script tries to run in / ??

Thx!
 

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,767
Hm, interesting ... but isn't disabling SIP just because of ordinary applescript a bit overkill !? Maybe there is a way to change script startup directory? How did you came to conclusion that script tries to run in / ??
Thx!
It's a temporary solution, until Apple fixes the problem.
I came to this conclusion by running adblock_hosts.sh from AppleScript, the temporary files are created in /
I've tried without succes with something like
do shell script "cd /users/user/documents/;" & "install.sh;" with administrator privileges
or
do shell script "cd /users/user/documents/;" & "sudo ./install.sh;" with administrator privileges
or
do shell script "cd /users/user/documents/;" & "sudo -s;" & "./install.sh;" with administrator privileges
I get Operation not permitted" number 126
Interestingly, do shell script "sudo -s" with administrator privileges doesn't get an error.
 

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,767
This might work
do shell script "sudo -s" with administrator privileges
do shell script "cd /users/user/documents/;" & "./install.sh;"
 

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
This might work
do shell script "sudo -s" with administrator privileges
do shell script "cd /users/user/documents/;" & "./install.sh;"

Unfortunately, 2nd line is executed, but NOT in privileged mode. If you append "with administrator privileges" to it, it fails as usual.

So you are sure, this is a bug in Catalina beta (i really hope so) and not something Apple just silently deprecated??
 

bogdanw

macrumors 603
Mar 10, 2009
5,746
2,767
So you are sure, this is a bug in Catalina beta (i really hope so) and not something Apple just silently deprecated??
I think it's a bug. You can try something else
tell application "Terminal"
activate
do script with command ("/users/user/documents/install.sh")
end tell
By the way, why do you need to run install.sh from AppleScript and do you run it every day? :)
 

zabukowski

macrumors newbie
Original poster
Sep 13, 2019
13
1
I think it's a bug. You can try something else
tell application "Terminal"
activate
do script with command ("/users/user/documents/install.sh")
end tell
By the way, why do you need to run install.sh from AppleScript and do you run it every day? :)

Applescript "do shell script with admin privileges" is a very simple way to perform user authorization and execute privileged script.

"install.sh" is basically an installer, which copies misc files all around the system, so it must have admin privileges.

Content of the install script is dynamically created. Applescript is fixed and it is called from the main app.

I know there are probably other ways to acomplish it, but this was always working as expected (tested from 10.9 to 10.14), now in Catalina is broken.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.