Looking to create an AppleScript for...

Discussion in 'Mac Programming' started by BasicGreatGuy, Jan 27, 2015.

  1. BasicGreatGuy Contributor

    BasicGreatGuy

    Joined:
    Sep 21, 2012
    Location:
    In the middle of several books.
    #1
    I am using a Mac app that still has a bluetooth bug in it. Developer is trying to sort it out. Until there is a permanent fix, (and I hope there is) I have to delete the following two bluetooth files. The first one is located in file:///Library/Preferences/com.apple.Bluetooth.plist. The second one is located in /Users/mynamehere/Library/Preferences/ByHost/com.apple.Bluetooth.BBF364CA-0E4F-5187-BEC8-70F07F316969.plist.

    Is it possible to create an AppleScript that would delete these two files at one time? If so, what is involved? I have never done anything like this before.
     
  2. brisskel macrumors newbie

    Joined:
    Jan 27, 2015
    #2
    Why an applescript? If you don't have any experience an automator script would probably be easiest. It would also be simple to do with a shell script.
     
  3. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #3
    I agree that if you're not familiar with AppleScript or shell scripting then an Automator action may be a better option. However, just for the sake of completeness, here's an AppleScript solution:

    Code:
    set theListOfFilesToDelete to {"/Users/Admin/Desktop/foo.txt", "/Users/Admin/Desktop/bar.txt", "/Users/Admin/Desktop/foobar.txt"}
    
    repeat with theFile in theListOfFilesToDelete
    	
    	try
    		set theFileToDelete to (POSIX file theFile) as alias
    		
    		tell application "Finder"
    			delete theFileToDelete
    		end tell
    	on error theErrorMessage
    		display alert "Delete failed" message theFile
    	end try
    end repeat
    ...just edit the list at the beginning to include the paths of any files you need deleting. It's a bit rough and ready. It doesn't consider whether the file(s) are in use or whether you have permissions to delete them. However, it'll probably work and if not then its a good starting point!

    Hope that's of some help.

    Good luck.
     
  4. chrfr macrumors 603

    Joined:
    Jul 11, 2009
    #4
    Depending on how widely you'd need to distribute this script, keep in mind that the files in ByHost are named specifically by computer. If you'd be using this on only one computer, this won't be an issue.
     
  5. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #5
    A good point. My solution only works if you're certain of the file names/paths you want to delete. If not then it gets a little more complex.
     

Share This Page