Solved

Delete folder from script

Posted on 2004-09-01
3
1,770 Views
Last Modified: 2013-12-26
I need to write an uninstallscript for an application. The script needs to delete a folder in the /Applications folder and delete a file from /etc/mach_init_per_user.d/
I need this script to be run from finder using a double click, but can not seem to get it right.

I have a bash script that works, but of course when double clicking in finder I simply get "There is no default application specified to open the document 'uninstall'". I tried it in Applescript, but I am afraid Applescript is not something you pick up in 1 hour.

Can someone translate this bash script to Applescript, or can tell me how to get the bash script to run from finder.

Thanks

Bash script:
#!/bin/bash
killall monitorApp
rm -Rf /Applications/MyApp
echo Root password required to delete file.
sudo rm /etc/mach_init_per_user.d/monitorApp.plist
0
Comment
Question by:bra033098
  • 2
3 Comments
 
LVL 2

Expert Comment

by:bachra04
ID: 11952083
// Please Try the following applescript
// you should have a file monitorApp.plist in the target location
//also you should change the password 12345 in this script by your password


with timeout of 1000 seconds
      try
            do shell script ¬
                  "killall monitorApp
                  rm -Rf /Applications/MyApp
                  sudo rm /etc/mach_init_per_user.d/monitorApp.plist" password "12345" with administrator privileges
      on error errormsg
            display dialog errormsg --in case anything goes wrong
      end try
end timeout

--BT

0
 

Author Comment

by:bra033098
ID: 11952376
BT

Thanks for the reply. So far so good. It works but there are some issues:
I need to distribute the script with an application, so I would not know the password for the machine it would be running on.
How do I make the little squigle after the "do shell script". My script works, but only because I moved killall to the end of the previous line.
Is there any way to ask the user to enter the admin password? (yes I know, very bad practice).

Finally, showing my ignorance as far as Mac and Applescript is concerned. When I save this txt file as uninstall.applescript, it only opens in Applescript Editor when I doubleclick it. I am clearly missing something very basic.

Thanks
0
 
LVL 2

Accepted Solution

by:
bachra04 earned 500 total points
ID: 11953070
//Is there any way to ask the user to enter the admin password? (yes I know, very bad //practice).

You simply have to omit password "12345"  in your script.
So the Applescript will be :
with timeout of 1000 seconds
     try
          do shell script ¬
               "killall monitorApp
               rm -Rf /Applications/MyApp
               sudo rm /etc/mach_init_per_user.d/monitorApp.plist"  with administrator privileges
     on error errormsg
          display dialog errormsg --in case anything goes wrong
     end try
end timeout



//Finally, showing my ignorance as far as Mac and Applescript is concerned. When I /////save this txt file as uninstall.applescript, it only opens in Applescript Editor when I //////doubleclick it. I am clearly missing something very basic.

Just save your script as an application and not as script.

--BT
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 379
abstract class with all non abstract mentods 6 76
Not needed 13 94
Capture logon name 13 37
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now