Permanently Delete Files With Applescript

Discussion in 'Mac Programming' started by noobsauce, Jun 11, 2010.

  1. noobsauce macrumors member

    Joined:
    Mar 23, 2010
    #1
    I am trying to make a simple script that permanently deletes my flash cache, but whenever I run the script neither of the files are deleted and the applescript window returns the result "". Is this script correct?
    Code:
    try
    	do shell script "rm -rf ~/Library/Preferences/Macromedia/Flash Player/#SharedObjects"
    	do shell script "rm -rf ~/Library/Preferences/Macromedia/Flash Player/macromedia.com"
    end try
    EDIT: The second ~/ has been removed
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Well the second rm line has two ~/ pieces in it that will screw things up.
     
  3. noobsauce thread starter macrumors member

    Joined:
    Mar 23, 2010
    #3
    I rewrote the script and it still does not work...
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Try adding \ before the space in the path in order to escape it, or add single quotes around the whole path. Also, you can catch any errors given.

    Code:
    try
    	do shell script "rm -rf ~/Library/Preferences/Macromedia/Flash\ Player/#SharedObjects"
    	do shell script "rm -rf ~/Library/Preferences/Macromedia/Flash\ Player/macromedia.com"
      on error error_message
        display alert error_message
    end try
     
  5. Caleb531 macrumors 6502

    Caleb531

    Joined:
    Oct 17, 2009
    #5
    Better yet, use the quoted form of the path to take care of the spaces automatically:

    Code:
    set thePath to "~/Library/Preferences/Macromedia/Flash Player/macromedia.com"
    set thPath to quoted form of thePath
     
  6. Bill McEnaney macrumors 6502

    Joined:
    Apr 29, 2010
    #6
    I don't know AppleScript, so I don't know the advantages of using it to delete those files. But why not just write a bash script that contains two "rm" commands? If I wanted to write something like this:

    rm -rf cache_1
    rm -rf cache_2

    Naturally, you need to replace "cache_1" and "cache_2" with names of the things you need to delete.

    Then I'd save the two lines in a file called, say "delete_caches" and type "chmod +x delete_caches" to make the script executable.
     
  7. noobsauce thread starter macrumors member

    Joined:
    Mar 23, 2010
    #7
    Does it have to be names or can I also use or paths? I am new to scripting.
     
  8. Weaselboy Moderator

    Weaselboy

    Staff Member

    Joined:
    Jan 23, 2005
    Location:
    California
    #8
    Sorry to resurrect an old post, but thought it might help people who discover this thread in a Google search.

    Use this Applescript with the asterisk in the Flash*Player section and it will work.

    Code:
    try
    	do shell script "rm -rf ~/Library/Preferences/Macromedia/Flash*Player/#SharedObjects"
    	do shell script "rm -rf ~/Library/Preferences/Macromedia/Flash*Player/macromedia.com"
    end try
     

Share This Page