Automated Bluetooth File Transfer

Hi, I only found out about this site today, while I was working on a script I use to transcode DVDs onto my laptop. I was looking to have the script send a message to my mobile phone via bluetooth to alert me when a DVD had finished ripping, but I didn’t manage to find any solutions here or elsewhere. Eventually, after much trial and error with GUI scripting, I managed to put together a script that would send a text file over to my phone using Bluetooth File Transfer, and I thought that some of you here might find it useful:

tell application "Finder"
	
	activate
	make new Finder window
	set target of Finder window 1 to item "textfile.txt" of folder "Random Folder" of startup disk
	
	tell application "System Events"
		tell process "Finder"
			tell menu bar 1
				tell menu bar item "Finder"
					tell menu "Finder"
						tell menu item "Services"
							tell menu "Services"
								click menu item "Send File To Bluetooth Device..."
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
	
	delay 5
	
	tell application "System Events"
		tell process "Bluetooth File Exchange"
			select row 1 of table of scroll area "Bluetooth Devices" of window 1
			click button "Send" of window 1
		end tell
	end tell
	
	activate
	select Finder window 1
	close Finder window 1
	
end tell

The one detail that might be worth worrying about is that it chooses the first bluetooth device in the list, rather than choosing a device by name. My phone always seems to be first on the list for me (perhaps the last-used device is listed first?), so it works fine for me, but you might want to have a look at what position the device you’re sending to will be in.

Hi,

nice script.
With AppleScript the Finder can open files directly using a certain application, GUI scripting is not needed for that task.
I added the functionality to specify the bluetooth device


property device : "K750i"
set fileToSend to alias "MacHD:Random Folder:textfile.txt"

tell application "Finder" to open fileToSend using application file id "com.apple.BluetoothFileExchange"
activate application "Bluetooth File Exchange"
tell application "System Events"
	tell process "Bluetooth File Exchange"
		repeat until exists window 1
			delay 0.5
		end repeat
		select (1st row of table of scroll area "Bluetooth Devices" of window 1 whose value of text field 1 is device)
		click button "Send" of window 1
	end tell
end tell

Hi

Trying to do something similar except I’m looping through a list of devices (hence the “row y”) and only sending to mobile phones, that bit is working but I’d like to catch any potential errors. Have I gone about this right by wrapping a “try” around it and then using an “on error”?


try
select (row y of table of scroll area "Bluetooth Devices" of window 1 whose value of text field 2 is devicetype)
click button "Send" of window 1
on error
click button "Close" of window 1
end try

The “on error” does not seem to catch an error such as the end user refusing the bluetooth msg. Also any other potential errors I might need to catch?

Garrett

Hi guys,

I am also trying to work out a way of sending a file via bluetooth to any detectable mobile phones within the computers proximity.
Does anyone have a suggestions on how to script this?

Many thanks in advance,

Schorsch