I am creating a script to delete some files (my purpose is to learn to use the dialogs and execute some tasks), I was building it based on examples on the net, the dialogs work fine, except when I want it to execute the commands sudo
, it tells me:
syntax error: End of line expected but identifier found. (-2741)
At first I tried to create a function to call it but it didn't work either, this is what I have so far:
#!/bin/sh
osascript <<EOT
app "System Events"
set answer to the button returned of (display dialog "Deseas eliminar MySQL?" buttons {"Si", "No"} default button 2)
#display dialog "You selected " & answer
if answer = "No" then
display dialog "Cancelado" buttons {"Aceptar"}
else
if (answer = "Si")then
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/var/mysql
sudo rm -rf /usr/local/mysql*
sudo rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
sudo rm -rf /var/db/receipts/com.mysql.*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*
launchctl unload -w ~/Library/LaunchAgents/com.mysql.mysql.plist
launchctl unload -w ~/Library/LaunchDaemons/com.st.plist
set answer to the button returned of (display dialog "Se ha eliminado MySQL, es necesario reiniciar.\nDeseas reiniciar ahora?" buttons {"Si","Reiniciar mas tarde"}default button 2)
end if
end if
return -- Suppress result
end
EOT
You can run osascript as sudo from the start instead of using sudo on every command and using
do shell script "código"
putting a ";" to separate each command: