Hey all,
I wrote a couple simple Applescripts to help me automate uploading to Dropbox. Both of them trigger when any file is added to the Public folder or any other folder under it.
Here's how the rule looks like:

The first script generates a Dropbox URL, shortens it using bit.ly and copies to clipboard. I use this service because it's a) reliable and b) I really like the "j.mp" domain name

Here's the first script. I save it as .scpt in Library > Scripts and call in Hazel. This method makes it a lot easier to maintain updates to the script across different computers.
- Code: Select all
on hazelProcessFile(theFile)
set login to "xxx"
set apikey to "xxx" --both login and apikey are from bit.ly
set db_ to "xxx" --your Dropbox ID
set path_ to "/" & my strip(theFile as text)
--set long URL
set url_ to "http://dl.dropbox.com/u/" & db_ & path_
--encode URL
set cmd to "/usr/bin/php -r 'echo trim(urlencode(" & "\"" & url_ & "" & "\"));'"
set url_ to (do shell script cmd)
--shorten URL
set cmd to "curl --stderr /dev/null 'https://api-ssl.bitly.com/v3/shorten?&login=" & login & "&apiKey=" & apikey & "&format=txt&uri=" & url_ & "'"
set url_ to (do shell script cmd)
set the clipboard to url_
end hazelProcessFile
on strip(theText)
set text item delimiters to (path to home folder as string) & "Dropbox:Public:" as text
set a to text items of theText
set b to item 2 of a
set text item delimiters to ":"
set a to text items of b
set text item delimiters to "/"
set path_ to a as text
set text item delimiters to ""
return path_
end strip
The second script displays a Growl notification. In order to make things as universal as possible, I have the main Growl script sitting in Scripts folder. It contains all subroutines related to displaying Growl notifications. And then I have a tiny script for Hazel, which calls the big one and lets me customize title and description of the notification.
Here's the general Growl script:
- Code: Select all
(* EXAMPLE OF USAGE
my notify("title", "description", "some path")
on notify(title_, description_, filepath_)
set growlscript to load script POSIX path of ((path to home folder as text) & "Dropbox:Library:Scripts:Snippets:" & "Growl Notifications" & ".scpt")
set growlscript's title_ to title_
set growlscript's description_ to description_
set growlscript's filepath_ to filepath_ as alias
growlscript's notify()
end notify
*)
property growlapp_ : "Misc Notifications"
property notifs_ : "Info"
property icon : "Growl.app"
property name_ : notifs_
property title_ : missing value
property description_ : missing value
property filepath_ : missing value
property pr : "2"
property list_ : {"public.jpeg", "public.tiff", "public.png"}
on notify()
tell application "Finder"
set path_ to filepath_
if path_ is "" then set path_ to (path to applications folder as text) & "Growl.app" as alias
set appname_ to name of file path_
set info_ to info for path_
set type_ to the type identifier of info_
end tell
if type_ is in the list_ then
my notifyimg(filepath_)
else if type_ is "com.apple.application-bundle" then
my notifyapp(appname_)
else
my notifyicon(filepath_)
end if
end notify
on register()
tell application id "com.Growl.GrowlHelperApp" to register as application growlapp_ all notifications notifs_ default notifications notifs_ icon of application icon
end register
on notifyimg(filepath_)
tell application id "com.Growl.GrowlHelperApp" to notify with name name_ title title_ description description_ application name growlapp_ priority pr image from location (filepath_ as alias)
end notifyimg
on notifyapp(appname_)
tell application id "com.Growl.GrowlHelperApp" to notify with name name_ title title_ description description_ application name growlapp_ priority pr icon of application appname_
end notifyapp
on notifyicon(filepath_)
tell application id "com.Growl.GrowlHelperApp" to notify with name name_ title title_ description description_ application name growlapp_ priority pr icon of file filepath_
end notifyicon
Save it to Library > Scripts > Snippets as "Growl Notifications.scpt".
Now, the script for Hazel rule:
- Code: Select all
set growlscript to load script POSIX path of ((path to home folder as text) & "Dropbox:Library:Scripts:Snippets:" & "Growl Notifications" & ".scpt")
tell application "Finder" to set growlscript's title_ to text 1 thru -5 of (get name of file theFile)
set growlscript's description_ to "Uploaded successfully!"
set growlscript's filepath_ to theFile as alias
growlscript's notify()
I hope someone will find this useful!