Macintosh Auto-Uploader for MBED programs

I wrote a little "Folder Action" Applescript that automatically takes the downloaded xxx_LPC1768.bin files from the MBED compiler and copies them from my main downloads directory into the MBED and also moves them into an MBED directory under my downloads directory. True one-button operation: hit the Compile button in the MBED compiler, then hit the reset button.

Just enable folder actions and attach this script to your downloads directory so that it is run when new files appear in that directory.


4 comments

13 Feb 2010
(*
This Folder Action handler is triggered whenever items are added to the attached folder.
The script will copy newly downloaded *_LPC*.bin files to the MBED, if any,
as well as moving the files to an MBED subdirectory.

By Ned Konz, ned@bike-nomad.com
February 13, 2010

License: MIT
*)
on adding folder items to this_folder after receiving these_items
	try
		set the destination_folder_name to "MBED"
		set the mbed_name to "/Volumes/MBED"
		set the mbed_folder to null
		set the mbed_directory to null
		set result_text to ""
		
		tell application "Finder"
			if not (exists folder destination_folder_name of this_folder) then
				make new folder at this_folder with properties {name:destination_folder_name}
			end if
			set the destination_folder to folder destination_folder_name of this_folder as alias
			set the destination_directory to POSIX path of the destination_folder
			(* set the mbed_folder to choose folder default location (POSIX file mbed_name) *)
			set the mbed_folder to (POSIX file mbed_name) as alias
			if (exists folder mbed_folder) then
				set the mbed_directory to POSIX path of the mbed_folder
			else
				set result_text to result_text & "Can't find " & mbed_name & return
			end if
		end tell
		
		repeat with i from 1 to number of items in these_items
			set this_item to item i of these_items
			set the item_info to info for this_item
			if this_item is not the destination_folder and ¬
				the name extension of the item_info is "bin" and ¬
				((the name of the item_info contains "_LPC1768") or (the name of the item_info contains "_LPC2368")) then
				set the item_path to the quoted form of the POSIX path of this_item
				set the destination_path to the quoted form of ¬
					(destination_directory & (name of the item_info))
				do shell script ("/bin/mv " & item_path & " " & destination_directory)
				set result_text to result_text & "moved " & item_path & " to " & destination_directory & return
			end if
			(* copy to the MBED itself *)
			if mbed_directory is not null then
				do shell script ("/bin/cp " & destination_path & " " & mbed_directory)
				set result_text to result_text & "copied " & item_path & " to " & mbed_directory & return
			end if
		end repeat
		
		display dialog result_text buttons {"OK"} default button 1
		
	on error the error_message number the error_number
		set the error_text to "Error: " & the error_number & ". " & the error_message
		-- the following line invokes the sub-routine to write the error into an error log created on the desktop
		-- if the file "MBED Copier Error Log.txt" already exists, it will add one line to the log
		my write_error_log(the error_text)
	end try
end adding folder items to

on write_error_log(this_error)
	set the error_log to ((path to desktop) as text) & "MBED Copier Error Log.txt"
	try
		open for access file the error_log with write permission
		write (this_error & return) to file the error_log starting at eof
		close access file the error_log
	on error
		try
			close access file the error_log
		end try
	end try
end write_error_log
19 Feb 2010

Amazing! Works just as advertised, just right click on the downloads folder, click setup folder actions, and then use that code as the script for the folder. Saves so much dragging :)

 

Thanks!

20 Feb 2010

You're welcome! Why click and then drag when you can just click?

11 Oct 2013 . Edited: 11 Oct 2013

Hi,

inspired by this I made a little Windows tool. If you find bugs or have suggestions please post. You run the tool and it does the rest so the only thing you need to do is click on "compile" and then the press the button of the mbed as soon as the "ding" is heard.

Simply enter the path and file name of source bin file, point to mbed and press run. It deletes the bin file after download to avoid the (1) in the file names. The file uploaded to mbed is always called code.bin so you dont have to bother if you have different names of source files.

Download at www.gearloose.net/mover.zip

You need to log in to post a comment