Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Apple_Robert

Contributor
Original poster
Sep 21, 2012
34,329
49,658
In the middle of several books.
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.
 

brisskel

macrumors newbie
Jan 27, 2015
1
0
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.
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
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.
 

chrfr

macrumors G5
Jul 11, 2009
13,520
7,043
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.

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.
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.