Dropbox Notification and Folder Creation

I get a lot of people in the company giving me files and the majority of them refuse to put them in my dropbox already contained in a folder. I have taken the original “dropboxNotify” script provided by Leopard and attempted to script additional items to it.

Basically what I want the script to do is when the files have been added that the script will create a folder with the date and time and then move all the files that were added to that folder.

This is what I have come up with, however the script no longer functions and I am slowly getting frustrated. I have a feeling it has to do with the date.


property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items
	set the_date to (current date)
	set new_folder_name to (date string of the_date) & "_" & (time string of the_date)
	tell application "Finder"
		make new folder at this_folder with properties {name:new_folder_name}
	end tell
	try
		tell application "Finder"
			--get the name of the folder
			set the folder_name to the name of this_folder
		end tell
		
		-- find out how many new items have been placed in the folder
		set the item_count to the number of items in the added_items
		
		-- move items added to dropbox to the timestamped folder
		tell application "Finder"
			move added_items of this_folder to new_folder_name
		end tell
		
		--create the alert string
		set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
		if the item_count is greater than 1 then
			set alert_message to alert_message & (the item_count as text) & " new items have "
		else
			set alert_message to alert_message & "One new item has "
		end if
		set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
		set the alert_message to (the alert_message & return & return & "Would you like to view the added items?")
		
		display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout
		set the user_choice to the button returned of the result
		
		if user_choice is "Yes" then
			tell application "Finder"
				--go to the desktop 
				activate
				--open the folder
				open this_folder
				--select the items
				reveal the added_items
			end tell
		end if
	end try
end adding folder items to

Thank you in advance for your help.

Hi,

I recommend to create the timestamped folders outside the hot folder,
because the event handler will be triggered again after creating any new folder,
which will cause an infinite loop

Try this, you have to adjust the path in the first line


property baseFolder : "MacHD:Users:myUser:Desktop:DropBox:"

property dialog_timeout : 30 -- set the amount of time before dialogs auto-answer.

on adding folder items to this_folder after receiving added_items
	tell (current date) to set new_folder_name to (its short date string) & "_" & (its hours & its minutes & its seconds)
	tell application "Finder"
		set timestampedFolder to make new folder at folder baseFolder with properties {name:new_folder_name}
	end tell
	try
		tell application "Finder"
			--get the name of the folder
			set the folder_name to the name of this_folder
		end tell
		
		-- find out how many new items have been placed in the folder
		set the item_count to the number of items in the added_items
		
		-- move items added to dropbox to the timestamped folder
		tell application "Finder"
			move added_items to timestampedFolder
		end tell
.


Edit: Thanks Adam, I changed the way to create the timestamp

The time string of a date has colons in it and you cannot use colons in the name of a folder or file.

That is beautiful!

Thank you for that.

I noticed the loop when I first got it to make the folder name. Didn’t even occur to me in the beginning.

This is great.

theEggplant

Well, now my boss is impressed. He wants the script installed for everyone who is running a MAC on our VPN to have it.
Is there anyway for the script to make a default drop box somewhere without having each person to edit it to show the script where the new drop box is? Also he wants to know if the username or some identifier of the computer that dropped it in the drop box could be added, ie. Date_User_Time.

In regards to the folder, I have tried a if exists folder statement and I am sure it might work but I am unsure how to get the “property baseFolder” to set automatically without pre-defining the location. Is it even possible? It would be great to have the new drop box just on the root of the drive when you double click it, and if for whatever reason it gets deleted the script will make sure that it exists.

this creates the folder in the home folder of the current user independent of the computer


on adding folder items to this_folder after receiving added_items
	
	set baseFolder to ((path to home folder as text) & "DropBox:")
	tell (current date) to set new_folder_name to (its short date string) & "_" & (its hours & its minutes & its seconds)
	tell application "Finder"
		if not (exists folder baseFolder) then make new folder at home with properties {name:"DropBox"}
		set timestampedFolder to make new folder at folder baseFolder with properties {name:new_folder_name}
	end tell
	try
		tell application "Finder"
			--get the name of the folder
.