How to execute commandLine with administrative privileges
Desired Workflow
I'm trying to find a way for the username and password window appear before execute the command line script!
Question
In Applscript we can execute a bash script with administrative privileges.
This means that the default window asking for the username and password appear before execute the script.
I don't know if this make any sense for you. I've tried with osascript but I didn't figure out the right sentence
Here is a video showing what I have but I want to add it to soundflow instead.
check at 37 second
https://www.dropbox.com/s/b17993kq8qu8dz3/Pro_Tools_Installer_2020.R2.0x117-AppInstall.mp4?dl=0
In this case I or we (users) already have the source and destination created, there's no need to choose them.
Thanks
Command Info
ID: user:-LEzGPe-OhWscuIf2MRu:cketc1vhx00029l10qcs30xn1
Source
//change the var to your path
var pythonScriptPath = "/Users/marco.bernardo/Documents/Scripts/Python/InstPTwVbeta_v07.py "
var sourceTarPath = "/Users/marco.bernardo/Downloads/ "
var destinationDMGPath = "/Users/marco.bernardo/Desktop/"
var executePythonScript = "python " + pythonScriptPath + sourceTarPath + destinationDMGPath
//log(executePythonScript)
//I need to find a way to execute python with administrator privileges (sudo) it needs to pop up the window asking for the user and password admin like Applescript can do
sf.system.exec({
commandLine: "python " + pythonScriptPath + sourceTarPath + destinationDMGPath
//commandLine: "osascript -e \"do shell script \\\"python " + pythonScriptPath + sourceTarPath + destinationDMGPath" & " -e \"with administrator privileges"
});
Links
User UID: zeVjM6FHntfwFzm79GRGlipkNSB3
Feedback Key: sffeedback:zeVjM6FHntfwFzm79GRGlipkNSB3:-MGfbGfNnOxBIOuBQHLQ
Christian Scheuer @chrscheuer2020-09-08 05:35:20.554ZThe easiest thing is probably to use this:
sf.system.execAppleScript({ script: `do shell script "python ${pythonScriptPath} ${sourceTarPath} ${destinationDMGPath}" with administrator privileges` });
Marco Bernardo @mbernardo2020-09-08 11:21:58.843ZWay more clean and PRO!! WoW
It didn't work.
I've open script editor and paste thisSCRIPT EDITOR
do shell script "python /Users/marco.bernardo/Documents/Scripts/Python/InstPTwVbeta_v07.py /Users/marco.bernardo/Downloads/ /Users/marco.bernardo/Desktop/" with administrator privileges
and I got this.error "/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file '/Users/marco.bernardo/Documents/Scripts/Python/InstPTwVbeta_v07.py': [Errno 1] Operation not permitted" number 2
IF I use the same command directly in the Terminal it works.TERMINAL
sudo python /Users/marco.bernardo/Documents/Scripts/Python/InstPTwVbeta_v07.py /Users/marco.bernardo/Downloads/ /Users/marco.bernardo/Desktop/I already check the path of my Python 2.7 and all seems correct!
I open the terminal and paste Python and is opening the correct version!`Python 2.7.15 (default, Jan 12 2019, 21:43:48)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.`
Weird...
Thank you Christian
Christian Scheuer @chrscheuer2020-09-08 12:06:34.479ZHm yea that's weird. You could try saving the python call into a shell script (and save as a .sh file) and then run that instead.
Christian Scheuer @chrscheuer2020-09-08 12:09:31.128ZOh no I see the issue. SoundFlow will normally make shell script execution work flawlessly so if it works in Terminal it'll work in our shell script execution --- but, here you're running the shell script via Apple Script and the Apple Script interpretation probably doesn't set up the proper environment variables and/or permissions for python to execute correctly.
Try instead writing a small shell script and place it in the same folder as your python file, and call it for example
InstPTwVbeta_v07.sh. Make sure to runchmod +x InstPTwVbeta_v07.sh. The script should just be the call to your python interpreter - make sure to pass the full path instead of using justpython.
Try running that shell script with sudo. Once you have everything working, then try running all that from osascript / SF's execAppleScript.
Christian Scheuer @chrscheuer2020-09-08 12:12:16.890ZWhat's the reason for running this via Python in the first place, by the way?
Python is known to be extremely tricky to get working reliably across different machines - so maybe there's a more stable alternative possible :)
Christian Scheuer @chrscheuer2020-09-08 12:13:32.411ZAh wait. I think you still need the
sudoin there:sf.system.execAppleScript({ script: `do shell script "sudo python ${pythonScriptPath} ${sourceTarPath} ${destinationDMGPath}" with administrator privileges` });
Marco Bernardo @mbernardo2020-09-08 12:44:44.306ZYeah it's very weird.
This is an Applescript app that I created a long time ago that executes a Python script with admin privileges and now I'm trying to use it with Soundflow without the hassle to convert it to SF pure code (when I start that I will need help for sure!!) hehe
It could be some security "issue" with macOS Catalina, I need to test this with macOS Mojave too but I think I will get the same issue.
My py is already with chmod +x (as I said above it works if I run in the terminal).
The issue is to execute the py with admin privileges (pop up window)
The sudo before the python didn't work too, I already tested before ;)
Here is a video showing what the Applescript and python is doing
I will send the link in private.
about Python I didn't use anything in the code besides what the 2.7 have by default and it's the default in all macOS since I can't remember.
But yes, if I want to use this with SF the best is to convert the py into SF
Christian Scheuer @chrscheuer2020-09-08 13:00:54.048ZHm yea then I think the issue is probably that the Apple Script runs as an actual super user..
Have you triedchmod a+xon the file to make sure the group+other permission bits are set for execute?
Marco Bernardo @mbernardo2020-09-08 13:51:35.327ZI didn't thought on that but It didn't work too.
Christian Scheuer @chrscheuer2020-09-08 16:12:58.935ZHm yea.. Then it's something going on with the Apple Script & the python environment not liking each other.
If you can get an osascript call to work in Terminal with the privileges dialog, then SF can easily just wrap that for you. So the real issue is coming up with the proper Apple Script -> Python call (outside of my SF expertise).
Marco Bernardo @mbernardo2020-09-08 18:46:36.020ZI just arrive at home where I have macOS Mojave the script works as it should.
Something in macOS have changed!! Argh....
Marco Bernardo @mbernardo2020-09-08 18:47:29.940Z2020-09-08 19:26:16.787ZQuestion:
What is the best way to get a variable of the home user of macOS?
I don't know how to do it with javascript! :/
I did search for home user and I didn't find it in the forum. I need to check again!!
Forget it!! duhhhhh
~/Desktop
Where I got the head !!
Christian Scheuer @chrscheuer2020-09-08 21:10:54.508ZYea you can use tilde in all SF paths. If you need the USER or any other environment variable, you can use this:
var username = sf.system.exec({ commandLine: 'echo $USER' }).result;
Marco Bernardo @mbernardo2020-09-08 23:00:10.004ZFound the "issue"!!
Is macOS Catalina f#"$#%%$& SIP
I disable SIP and all it's working.
Gonna enable it again to see if it continue to work.
Marco Bernardo @mbernardo2020-09-09 00:15:07.401ZNah If I enable SIP again the script stops working in macOS Catalina.
I already add almost I can remember into the Security & Privacy - Full disk Access.
Marco Bernardo @mbernardo2020-09-09 01:02:31.269ZIf I use it on a terminal window it work (macOS Catalina)
sudo python /Users/marco.bernardo/Documents/Scripts/Python/InstPTwVbeta_v07.py /Users/marco.bernardo/Downloads/ /Users/marco.bernardo/Desktop/The "issue" is really the SIP in macOS Catalina.
Christian Scheuer @chrscheuer2020-09-09 10:03:30.493Z:/
Marco Bernardo @mbernardo2020-09-09 10:24:44.204ZI need to create a macro for the macOS Catalina and beyond that opens the terminal paste the code line and execute then we enter the password in the terminal instead of the pop window that is standard in all the apps.
For macOS Mojave the script works ok.
and that's all "folks" "We got to love" SIP!! eheheh