Screen shots and files sharing with Dropbox

Sharing and discussing custom actions for LaunchBar
aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Screen shots and files sharing with Dropbox

Post by aristidesfl » Tue Mar 02, 2010 4:01 am

This is a script based on iRounak's screenshot sharing script that can be found at http://forums.obdev.at/viewtopic.php?f=24&t=3448
Features Added:
- Screenshot with default name without having to enter a name
- Sharing of Files (not only screenshots)
- Growl notifications with dropbox icon
- Cancel buttons does not generate an error dialog

Code: Select all

--Two changes to be made before you use this script
--1. Find this line in the script below and change it to the path to your Dropbox Public folder.
--2. Observe one of your Dropbox URLs and you will notice that there are some numbers in those URLs. That is your Dropbox id.
--Find this line in the script below and change it to your Dropbox id instead of 123456
-------------------------------------------------------------------
--How to use? 3 diferent ways:
--1*************
--Bring this script in LaunchBar, press space and type the name that you would like to give to that screenshot and press return
--e.g. myname
--you will see a cross-hair, you can start selecting the region that you want a screenshot of or you can press "space" key and take a screenshot of a window
--This will generate screenshot named myname in png format in your Dropbox folder
--you can also enter the format of the image
--e.g. myname, jpg
--note that the syntax is <name><comma><space><format>

--2**************
--Bring this script in LaunchBar and press return
--you will see a cross-hair, you can start selecting the region that you want a screenshot of or you can press "space" key and take a screenshot of a window
--This will generate screenshot with an automatic name in your Dropbox folder

--3***************
--Select a file using Launch bar and open it with this script by pressing tab, finding the script and pressing enter.
--The file will be copied to the dropbox public folder


-------------------------------------------------------------------
--What will happen after you run this script?
--once you have done that, Dropbox will upload the image/file. The public url will be shortened and copied to your clipboard and it will also be sent to LaunchBar in case you wanted to check if the image has been uploaded properly. Be patient before checking it. Observe the Dropbox icon in your menu bar to make sure that the upload has finished. Otherwise you will get 404 error.
--Let me know if you found this script useful or not. This will help me understand whether I must spend time writing instructions and posting such scripts or not........
-- Original screenshot script by iRounak
-- Improved with:
-- -Screenshot with default name without having to enter a name
-- -Sharing of Files (not only screenshots)
-- -Growl notifications with dropbox icon
-- -Cancel buttons does not generate an error dialog
-- by aristidesfl



--***********************************************************************************
--MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE!
--***********************************************************************************

property dropboxID : 123456 --> Replace this number with your dropbox ID
property ifolder : "Macintosh HD:Users:John:Dropbox:Public:" --> Replace this path with your dropbox public folder path (you have to use the ": format" instead of "/Users/John/Dropbox/Public/"

--***********************************************************************************
--MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE!
--***********************************************************************************


on run
   try
      
      if application "Dropbox" is not running then launch application "Dropbox"
      tell application "LaunchBar" to hide
      
      set {year:y, month:m, day:d, hours:h, minutes:m, seconds:s} to (current date)
      set theDate to (y & "-" & m * 1 & "-" & d & " at " & h & "h" & m & "m" & s & "s")
      
      set theformat to "png"
      set thename to "Screen shot " & theDate & "." & theformat
      set the_file to ""
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
end run

on open (the_file)
   try
      
      if application "Dropbox" is not running then launch application "Dropbox"
      tell application "LaunchBar" to hide
      try
         set text item delimiters to ":"
         set thename to last text item of (the_file as text)
         set text item delimiters to ""
      on error
         set text item delimiters to ""
      end try
      
      
      set theformat to "file"
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
   
   
end open

on handle_string(thetext)
   try
      
      if application "Dropbox" is not running then launch application "Dropbox"
      tell application "LaunchBar" to hide
      
      set AppleScript's text item delimiters to ","
      set thename to first text item of thetext
      set theformat to false
      try
         set theformat to text 2 thru -1 of second text item of thetext
      end try
      if theformat is false then set theformat to "png"
      set AppleScript's text item delimiters to ""
      set thename to thename & "." & theformat as text
      set the_file to ""
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
   on error e
      tell me to activate
      display dialog e
   end try
end handle_string


-------------------------------------------------------------------
--Handlers
-------------------------------------------------------------------


on dupcheck(thename, ifolder, theformat, dropboxID, the_file)
   set thedupcheck to ifolder & thename
   tell me to activate
   
   tell application "Finder" to if not (exists (POSIX path of thedupcheck) as POSIX file) then
      --Changed Lines******************************************************   
      set thedecision to my processitem(thename, ifolder, theformat, dropboxID, the_file)
   else
      tell me to activate
      set thedisplay to display dialog "An item with the name \"" & thename & "\" already exists in the destination" buttons {"Cancel ", "Rename", "Replace"} default button "Replace"
      
      if button returned of thedisplay is "Replace" then
         my processreplace(thename, ifolder, theformat, dropboxID, the_file)
      else if button returned of thedisplay is "Rename" then
         my processrename(thename, ifolder, theformat, dropboxID, the_file)
      else
         return "Canceled"
         
      end if
   end if
end dupcheck

on processitem(thename, ifolder, theformat, dropboxID, the_file)
   growlRegister()
   if theformat = "file" then
      tell application "Finder" to copy file the_file to folder ifolder
      growlNotify("Uploading file ", thename)
      
   else if theformat = "filerename" then
      set thecmd to "cp " & (POSIX path of the_file) & " " & (POSIX path of ifolder) & thename
      do shell script thecmd
      growlNotify("Uploading file ", thename)
   else
      set ifile to ifolder & thename
      set qifile to quoted form of (POSIX path of ifile)
      set thecmd to "screencapture -i -t " & theformat & " " & qifile
      do shell script thecmd
      growlNotify("Uploading screenshot ", thename)
      
   end if
   my processurl(thename, dropboxID)
   
   
end processitem

on processreplace(thename, ifolder, theformat, dropboxID, the_file)
   set ifile to ifolder & thename
   set qifile to quoted form of (POSIX path of ifile)
   do shell script "rm -r " & qifile
   set qifolder to quoted form of (POSIX path of ifolder)
   my processitem(thename, ifolder, theformat, dropboxID, the_file)
end processreplace

on processrename(thename, ifolder, theformat, dropboxID, the_file)
   repeat
      set AppleScript's text item delimiters to "."
      set theonlyname to text items 1 thru -2 of thename
      set thenameextension to last text item of thename
      set AppleScript's text item delimiters to ""
      tell me to activate
      set thename to text returned of (display dialog "Enter the new name: (This dialog box will reappear if an item with the new name you specified also exists in the destination folder)" default answer theonlyname)
      set thename to thename & "." & thenameextension
      set thenewcheck to ifolder & thename
      
      if theformat = "file" then set theformat to "filerename"
      
      tell application "Finder" to if not (exists (POSIX path of thenewcheck) as POSIX file) then
         my processitem(thename, ifolder, theformat, dropboxID, the_file)
         exit repeat
      end if
   end repeat
end processrename
on processurl(thename, dropboxID)
   try
      set AppleScript's text item delimiters to " "
      set thename to text items of thename
      set AppleScript's text item delimiters to "%20"
      set thename to thename as string
      set AppleScript's text item delimiters to ""
   end try
   set theurl to "http://dl.getdropbox.com/u/" & dropboxID & "/" & thename
   set curlCMD to ¬
      "curl --stderr /dev/null \"http://u.nu/unu-api-simple?url=" & theurl & "\""
   set theurl to (do shell script curlCMD)
   set the clipboard to theurl
   tell application "LaunchBar"
      set selection as text to theurl
      activate
   end tell
end processurl



-- additional scripting for Growlnotification
using terms from application "GrowlHelperApp"
   on growlRegister()
      tell application "GrowlHelperApp"
         register as application "Share with Dropbox" all notifications {"Alert"} default notifications {"Alert"} icon of application "Dropbox.app"
      end tell
   end growlRegister
   on growlNotify(grrTitle, grrDescription)
      tell application "GrowlHelperApp"
         notify with name "Alert" title grrTitle description grrDescription application name "Share with Dropbox"
      end tell
   end growlNotify
end using terms from

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Screen shots and files sharing with Dropbox

Post by aristidesfl » Mon Sep 06, 2010 11:26 pm

Updated to fix url shortener
PS:(You have to place your dropbox ID in the beginning of code where it says so)

Code: Select all


--***********************************************************************************
--MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE!
--***********************************************************************************
property dropboxID : 1234567 --> Replace this number with your Dropbox ID*
--***********************************************************************************
--MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE! MODIFY HERE!
--***********************************************************************************

--*Observe one of your Dropbox URLs and you will notice that there are some numbers in those URLs. That is your Dropbox id.








--How to use? 3 diferent ways:
--1*************
--Bring this script in LaunchBar, press space and type the name that you would like to give to that screenshot and press return
--e.g. myname
--you will see a cross-hair, you can start selecting the region that you want a screenshot of or you can press "space" key and take a screenshot of a window
--This will generate screenshot named myname in png format in your Dropbox folder
--you can also enter the format of the image
--e.g. myname, jpg
--note that the syntax is <name><comma><space><format>

--2**************
--Bring this script in LaunchBar and press return
--you will see a cross-hair, you can start selecting the region that you want a screenshot of or you can press "space" key and take a screenshot of a window
--This will generate screenshot with an automatic name in your Dropbox folder

--3***************
--Select a file using Launch bar and open it with this script by pressing tab, finding the script and pressing enter.
--The file will be copied to the dropbox public folder


-------------------------------------------------------------------
--What will happen after you run this script?
--once you have done that, Dropbox will upload the image/file. The public url will be shortened and copied to your clipboard and it will also be sent to LaunchBar in case you wanted to check if the image has been uploaded properly. Be patient before checking it. Observe the Dropbox icon in your menu bar to make sure that the upload has finished. Otherwise you will get 404 error.
--Let me know if you found this script useful or not. This will help me understand whether I must spend time writing instructions and posting such scripts or not........
-- Original screenshot script by iRounak
-- Improved with:
-- -Screenshot with default name
-- -Sharing of Files
-- -Growl notifications
-- -Cancel buttons now does not generate another dialog
-- by aristidesfl


property ifolder : {path to home folder as string, "Dropbox:Public:"} as string

on run
   try
      
      if application "Dropbox" is not running then launch application "Dropbox"
      tell application "LaunchBar" to hide
      
      set {year:y, month:m, day:d, hours:h, minutes:m, seconds:s} to (current date)
      set theDate to (y & "-" & m * 1 & "-" & d & " at " & h & "h" & m & "m" & s & "s")
      
      set theformat to "png"
      set thename to "Screen shot " & theDate & "." & theformat
      set the_file to ""
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
end run

on open (the_file)
   try
      
      if application "Dropbox" is not running then launch application "Dropbox"
      tell application "LaunchBar" to hide
      try
         set text item delimiters to ":"
         set thename to last text item of (the_file as text)
         set text item delimiters to ""
      on error
         set text item delimiters to ""
      end try
      
      
      set theformat to "file"
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
   
   
end open

on handle_string(thetext)
   try
      
      if application "Dropbox" is not running then launch application "Dropbox"
      tell application "LaunchBar" to hide
      
      set AppleScript's text item delimiters to ","
      set thename to first text item of thetext
      set theformat to false
      try
         set theformat to text 2 thru -1 of second text item of thetext
      end try
      if theformat is false then set theformat to "png"
      set AppleScript's text item delimiters to ""
      set thename to thename & "." & theformat as text
      set the_file to ""
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
   on error e
      tell me to activate
      display dialog e
   end try
end handle_string


-------------------------------------------------------------------
--Handlers
-------------------------------------------------------------------


on dupcheck(thename, ifolder, theformat, dropboxID, the_file)
   set thedupcheck to ifolder & thename
   tell me to activate
   
   tell application "Finder" to if not (exists (POSIX path of thedupcheck) as POSIX file) then
      --Changed Lines******************************************************   
      set thedecision to my processitem(thename, ifolder, theformat, dropboxID, the_file)
   else
      tell me to activate
      set thedisplay to display dialog "An item with the name \"" & thename & "\" already exists in the destination" buttons {"Cancel ", "Rename", "Replace"} default button "Replace"
      
      if button returned of thedisplay is "Replace" then
         my processreplace(thename, ifolder, theformat, dropboxID, the_file)
      else if button returned of thedisplay is "Rename" then
         my processrename(thename, ifolder, theformat, dropboxID, the_file)
      else
         return "Canceled"
         
      end if
   end if
end dupcheck

on processitem(thename, ifolder, theformat, dropboxID, the_file)
   growlRegister()
   if theformat = "file" then
      tell application "Finder" to copy file the_file to folder ifolder
      growlNotify("Uploading file ", thename)
      
   else if theformat = "filerename" then
      set thecmd to "cp " & (POSIX path of the_file) & " " & (POSIX path of ifolder) & thename
      do shell script thecmd
      growlNotify("Uploading file ", thename)
   else
      set ifile to ifolder & thename
      set qifile to quoted form of (POSIX path of ifile)
      set thecmd to "screencapture -i -t " & theformat & " " & qifile
      do shell script thecmd
      growlNotify("Uploading screenshot ", thename)
      
   end if
   my processurl(thename, dropboxID)
   
   
end processitem

on processreplace(thename, ifolder, theformat, dropboxID, the_file)
   set ifile to ifolder & thename
   set qifile to quoted form of (POSIX path of ifile)
   do shell script "rm -r " & qifile
   set qifolder to quoted form of (POSIX path of ifolder)
   my processitem(thename, ifolder, theformat, dropboxID, the_file)
end processreplace

on processrename(thename, ifolder, theformat, dropboxID, the_file)
   repeat
      set AppleScript's text item delimiters to "."
      set theonlyname to text items 1 thru -2 of thename
      set thenameextension to last text item of thename
      set AppleScript's text item delimiters to ""
      tell me to activate
      set thename to text returned of (display dialog "Enter the new name: (This dialog box will reappear if an item with the new name you specified also exists in the destination folder)" default answer theonlyname)
      set thename to thename & "." & thenameextension
      set thenewcheck to ifolder & thename
      
      if theformat = "file" then set theformat to "filerename"
      
      tell application "Finder" to if not (exists (POSIX path of thenewcheck) as POSIX file) then
         my processitem(thename, ifolder, theformat, dropboxID, the_file)
         exit repeat
      end if
   end repeat
end processrename
on processurl(thename, dropboxID)
   try
      set AppleScript's text item delimiters to " "
      set thename to text items of thename
      set AppleScript's text item delimiters to "%20"
      set thename to thename as string
      set AppleScript's text item delimiters to ""
   end try
   set theurl to "http://dl.getdropbox.com/u/" & dropboxID & "/" & thename
   set curlCMD to ¬
      "curl --stderr /dev/null \"http://is.gd/api.php?longurl=" & theurl & "\""
   set theurl to (do shell script curlCMD)
   set the clipboard to theurl
   tell application "LaunchBar"
      set selection as text to theurl
      activate
   end tell
end processurl



-- additional scripting for Growlnotification
using terms from application "GrowlHelperApp"
   on growlRegister()
      tell application "GrowlHelperApp"
         register as application "Share with Dropbox" all notifications {"Alert"} default notifications {"Alert"} icon of application "Dropbox.app"
      end tell
   end growlRegister
   on growlNotify(grrTitle, grrDescription)
      tell application "GrowlHelperApp"
         notify with name "Alert" title grrTitle description grrDescription application name "Share with Dropbox"
      end tell
   end growlNotify
end using terms from


aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Screen shots and files sharing with Dropbox

Post by aristidesfl » Fri Nov 05, 2010 3:11 am

New version: https://gist.github.com/663278

Bug fixes:
- Wrong path when syncing script with dropbox thru computers with different account names

Features:
- New url shortener: http://tinyarro.ws/
- Name of file included in shortened url if not too big
- Support for sharing folders and apps (by zipping them)

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Screen shots and files sharing with Dropbox

Post by ptujec » Sun Jan 30, 2011 10:18 pm

Today I unfortunately reached my Cloudapp upload limited. So I stumbled upon you script. Thanks! It works great. I changed a few things though …
I added "Growl priority" and a Growl notification for "on error". Also added Cloudapp support (ShortURL) and skiped the selecting ShortURL part. Instead I added a Growl notification.

!!! You have to create a keychain entry → See details !!!

Code: Select all

-- https://github.com/aristidesfl/launchbar-scripts
-- Share via Dropbox
-- by aristidesfl
--
-- modified by Ptujec 2011-01-30
--    added:
--       - Growl priority
--      - Growl Notification for "on error"
--    changed
--       - Cloudapp support (ShortURL)
--       - Notification instead of selecting ShortURL

--USAGES:
--1. To share a file/folder, select it and send it to this action
--2. To share a screenshot select this action and press return
--3. To share a screenshot with a name, selecte this action, press space, enter a name and press return


--============== MODIFY HERE ===================--

property dropboxID : 123456 --> Replace this number with your dropbox ID

--============== MODIFY HERE ===================--

on run
   try
      
      if application "Dropbox" is not running then launch application "Dropbox"
      set ifolder to {path to home folder as string, "Dropbox:Public:"} as string
      tell application "LaunchBar" to hide
      
      set {year:y, month:m, day:d, hours:h, minutes:m, seconds:s} to (current date)
      set theDate to (h & "h" & m & "m" & s & "s")
      
      set theformat to "png"
      set thename to "screenshot" & theDate & "." & theformat
      set the_file to ""
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
      
   on error e
      my growlRegister()
      growlNotify("Error", e, 2)
   end try
end run

on open (the_file)
   try
      
      if application "Dropbox" is not running then launch application "Dropbox"
      set ifolder to {path to home folder as string, "Dropbox:Public:"} as string
      
      tell application "LaunchBar" to hide
      try
         set text item delimiters to ":"
         set thename to last text item of (the_file as text)
         set theformat to "file"
         
         if thename = "" then
            set thename to text item ((count of text items of (the_file as text)) - 1) of (the_file as text)
            set theformat to "folder"
            
         end if
         set suggest to "&suggest=" & thename
         set text item delimiters to ""
      on error
         set text item delimiters to ""
      end try
      
      
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
      
   on error e
      my growlRegister()
      growlNotify("Error", e, 2)
   end try
   
   
end open

on handle_string(thetext)
   try
      
      
      if application "Dropbox" is not running then launch application "Dropbox"
      set ifolder to {path to home folder as string, "Dropbox:Public:"} as string
      
      tell application "LaunchBar" to hide
      
      set AppleScript's text item delimiters to ","
      set thename to first text item of thetext
      set theformat to false
      try
         set theformat to text 2 thru -1 of second text item of thetext
      end try
      if theformat is false then set theformat to "png"
      set AppleScript's text item delimiters to ""
      set thename to thename & "." & theformat as text
      set suggest to "&suggest=" & thename
      set the_file to ""
      set thecmd to my dupcheck(thename, ifolder, theformat, dropboxID, the_file)
      
   on error e
      my growlRegister()
      growlNotify("Error", e, 2)
   end try
end handle_string


-------------------------------------------------------------------
--Handlers
-------------------------------------------------------------------


on dupcheck(thename, ifolder, theformat, dropboxID, the_file)
   set thedupcheck to ifolder & thename
   if theformat = "folder" then
      set thedupcheck to thedupcheck & ".zip"
   end if
   tell me to activate
   
   tell application "Finder" to if not (exists (POSIX path of thedupcheck) as POSIX file) then
      --Changed Lines******************************************************   
      set thedecision to my processitem(thename, ifolder, theformat, dropboxID, the_file)
   else
      tell me to activate
      set thedisplay to display dialog "An item with the name \"" & thename & "\" already exists in the destination" buttons {"Cancel ", "Rename", "Replace"} default button "Replace"
      
      if button returned of thedisplay is "Replace" then
         my processreplace(thename, ifolder, theformat, dropboxID, the_file)
      else if button returned of thedisplay is "Rename" then
         my processrename(thename, ifolder, theformat, dropboxID, the_file)
      else
         return "Canceled"
         
      end if
   end if
end dupcheck

on processitem(thename, ifolder, theformat, dropboxID, the_file)
   growlRegister()
   if theformat = "file" then
      tell application "Finder" to copy file the_file to folder ifolder
      growlNotify("Uploading file ", thename, 0)
      
   else if theformat = "folder" then
      do shell script "zip -r " & (POSIX path of ifolder) & thename & " " & (POSIX path of the_file) & ""
      set thename to thename & ".zip"
      growlNotify("Uploading file ", thename, 0)
      
   else if theformat = "filerename" then
      set thecmd to "cp " & (POSIX path of the_file) & " " & (POSIX path of ifolder) & thename
      do shell script thecmd
      growlNotify("Uploading file ", thename, 0)
   else
      set ifile to ifolder & thename
      set qifile to quoted form of (POSIX path of ifile)
      set thecmd to "screencapture -i -t " & theformat & " " & qifile
      do shell script thecmd
      growlNotify("Uploading screenshot ", thename, 0)
      
   end if
   my processurl(thename, dropboxID)
   
   
end processitem

on processreplace(thename, ifolder, theformat, dropboxID, the_file)
   
   set ifile to ifolder & thename
   if theformat = "folder" then
      set ifile to ifile & ".zip"
   end if
   set qifile to quoted form of (POSIX path of ifile)
   do shell script "rm -r " & qifile
   set qifolder to quoted form of (POSIX path of ifolder)
   my processitem(thename, ifolder, theformat, dropboxID, the_file)
end processreplace

on processrename(thename, ifolder, theformat, dropboxID, the_file)
   repeat
      set AppleScript's text item delimiters to "."
      set theonlyname to text items 1 thru -2 of thename
      set thenameextension to last text item of thename
      set AppleScript's text item delimiters to ""
      tell me to activate
      set thename to text returned of (display dialog "Enter the new name: (This dialog box will reappear if an item with the new name you specified also exists in the destination folder)" default answer theonlyname)
      if theformat is not equal to "folder" then
         set thename to thename & "." & thenameextension
      end if
      set thenewcheck to ifolder & thename
      
      if theformat = "file" then set theformat to "filerename"
      
      tell application "Finder" to if not (exists (POSIX path of thenewcheck) as POSIX file) then
         my processitem(thename, ifolder, theformat, dropboxID, the_file)
         exit repeat
      end if
   end repeat
end processrename
on processurl(thename, dropboxID)
   try
      set AppleScript's text item delimiters to " "
      set thename to text items of thename
      set AppleScript's text item delimiters to ""
      set suggest to "&suggest=" & thename as string
      set wordcount to do shell script "echo " & quoted form of suggest & " | wc -c"
      set wordcount to do shell script "echo " & quoted form of wordcount & " | sed 's/^[    ]*//'"
      if wordcount > 25 then
         set suggest to ""
      end if
      set AppleScript's text item delimiters to "%20"
      set thename to thename as string
      set AppleScript's text item delimiters to ""
   end try
   set theurl to "http://dl.getdropbox.com/u/" & dropboxID & "/" & thename
   set shortURL to shortenURL(theurl)
   
   set the clipboard to shortURL
   -- tell application "LaunchBar"
   -- set selection as text to shortURL
   -- activate
   -- end tell
   growlNotify("ShortURL copied to clipboard", shortURL, 0)
   
   
   
end processurl

--
on shortenURL(theurl) -- via Cloudapp
   
   tell application "Keychain Scripting"
      set cloud_key to first generic key of current keychain whose name is "Cloud"
      set Username to account of cloud_key
      set Pword to password of cloud_key
   end tell
   
   --
   set curlCMD to "curl --digest -u '" & Username & ":" & Pword & "' -H 'Accept: application/json' -H 'Content-Type: application/json' -d '{ \"item\": { \"name\": \"" & theurl & "\", \"redirect_url\": \"" & theurl & "\" } }' http://my.cl.ly/items"
   
   set shortURL to (do shell script curlCMD)
   set oset to offset of "http://cl.ly/" in shortURL
   set shortURL to text (oset) thru (oset + 16) of shortURL
   return shortURL
end shortenURL


-- additional scripting for Growlnotification
on growlRegister()
   tell application "GrowlHelperApp"
      register as application "Share with Dropbox" all notifications {"Alert"} default notifications {"Alert"} icon of application "Dropbox.app"
   end tell
end growlRegister
on growlNotify(grrTitle, grrDescription, grrPriority)
   tell application "GrowlHelperApp"
      notify with name "Alert" title grrTitle description grrDescription priority grrPriority application name "Share with Dropbox"
   end tell
end growlNotify
Last edited by ptujec on Sun Jan 30, 2011 11:35 pm, edited 3 times in total.

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Screen shots and files sharing with Dropbox

Post by aristidesfl » Sun Jan 30, 2011 11:26 pm

Hi ptujec,

thanks for referring to my gist, but please consider exchanging it by my github repository: https://github.com/aristidesfl/launchbar-scripts


I've never used cloudapp before but decided to give it a try in order to try to understand why you are using they link shortener instead.
(The script didn't work because it didn't find any Cloudapp credentials in the keychain)
After installing and entering my Cloudapp credentials, the script is working. The problem is that the shortened links given back, don't point to the uploaded files, but to random files of other people. Sometime they even say that the link is invalid.
Is this working for you?

There is a couple of things I didn't undestand.

1. What is the advantage of using Cloudapp's link shortening services?
2. What is the point of skipping the select shorted link part? Before you could just press enter to opening the link. Now you can't do that and you even have to dismiss launchbar.


Cheers

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Screen shots and files sharing with Dropbox

Post by aristidesfl » Sun Jan 30, 2011 11:44 pm

It seems that the shorten links are being cut and only the beginning is being returned.

Example:

http://cl.ly/2k280k3x3N3a3m2H3l2A --> http://cl.ly/2k28

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Screen shots and files sharing with Dropbox

Post by ptujec » Mon Jan 31, 2011 12:01 am

aristidesfl wrote:Hi ptujec,

thanks for referring to my gist, but please consider exchanging it by my github repository: https://github.com/aristidesfl/launchbar-scripts


I've never used cloudapp before but decided to give it a try in order to try to understand why you are using they link shortener instead.
(The script didn't work because it didn't find any Cloudapp credentials in the keychain)
After installing and entering my Cloudapp credentials, the script is working. The problem is that the shortened links given back, don't point to the uploaded files, but to random files of other people. Sometime they even say that the link is invalid.
Is this working for you?

There is a couple of things I didn't undestand.

1. What is the advantage of using Cloudapp's link shortening services?
2. What is the point of skipping the select shorted link part? Before you could just press enter to opening the link. Now you can't do that and you even have to dismiss launchbar.


Cheers


I fixed the link and pointed to an entry which explains the keychain thing.

1. Stats
Image
… and it allowing me to use drag&drop if I want to

2. Thats strange … doesn't happen here? Maybe because of nonactivating mode?

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Screen shots and files sharing with Dropbox

Post by aristidesfl » Mon Jan 31, 2011 12:34 am

My 2 choices when it comes to url shorting services are:
1. tinyarro.ws
- Coolest and shorter links ever: http://☁.ws/쇝
- Allows the usage a descriptive name instead: http://☁.ws/namexample.png
- Shows users the real url before redirecting
2. goo.gl
- the fastest. period.
- works on twitter (tinyarro.ws recently broken after a twitter update)

Both of them support statistics

The problem with cloudapp is that the shorten links are not short at all (http://cl.ly/2k280k3x3N3a3m2H3l2A) and it needs to be running all the time..
not worth just to have drag and drop support..when there is launchbar's instant send.

It is the nonactivating mode indeed but I need it disabled because I'm using keyboardremap4macbook to change some behaviour when launchbar is active.

It would be really great if you could send me a patch with the growl improvements tough..

ptujec
Wizard
Wizard
Posts: 321
Joined: Fri Dec 19, 2008 11:36 am
Contact:

Re: Screen shots and files sharing with Dropbox

Post by ptujec » Mon Jan 31, 2011 12:50 am

aristidesfl wrote:My 2 choices when it comes to url shorting services are:
The problem with cloudapp is that the shorten links are not short at all (http://cl.ly/2k280k3x3N3a3m2H3l2A) and it needs to be running all the time..
…It would be really great if you could send me a patch with the growl improvements tough..

I guess its a matter of taste. But you can set it up to have shorter urls …

There is not much to change regarding Growl:
Image
… the on error part should be self explaining I guess
More info → http://growl.info/documentation/applescript-support.php

ccjensen
Posts: 1
Joined: Wed Mar 02, 2011 6:47 am

Re: Screen shots and files sharing with Dropbox

Post by ccjensen » Wed Mar 02, 2011 6:53 am

My version. I don't like to use url shorteners, so removed that.
Added the folder format:
~/Dropbox/Public/Shared_Files/2010-12-01/filename.jpg

It only checks for duplicates within the same folder, and it replaces spaces file/folder names with underscores (except in the case where the user requests to rename).
It does screenshots as "screenshot_19-22-36.png"

Code: Select all

--Based upon https://github.com/aristidesfl/launchbar-scripts/blob/master/Share%20Dropbox.applescript

--================================== Modify Here =========================================--

property dropboxID : 123456 --> Replace this number with your dropbox ID

--================================== Modify Here =========================================--

--Usages:
--1. To share a file/folder, select it and send it to this action
--2. To share a screenshot select this action and press return
--3. To share a screenshot with a name, selecte this action, press space, enter a name and press return

on run
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      tell application "LaunchBar" to hide
      
      set theTime to (do shell script "date '+%H-%M-%S'")
      set theformat to "png"
      set filename to "screenshot_" & theTime & "." & theformat
      set the_file to ""
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
end run

on open (the_file)
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      
      tell application "LaunchBar" to hide
      try
         set text item delimiters to ":"
         set filename to last text item of (the_file as text)
         set theformat to "file"
         
         if filename = "" then
            set filename to text item ((count of text items of (the_file as text)) - 1) of (the_file as text)
            set theformat to "folder"
            
         end if
         set suggest to "&suggest=" & filename
         set text item delimiters to ""
      on error
         set text item delimiters to ""
      end try
      
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
   
   
end open

on handle_string(theText)
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      
      tell application "LaunchBar" to hide
      
      set AppleScript's text item delimiters to ","
      set filename to first text item of theText
      set theformat to false
      try
         set theformat to text 2 thru -1 of second text item of theText
      end try
      if theformat is false then set theformat to "png"
      set AppleScript's text item delimiters to ""
      set filename to filename & "." & theformat as text
      set suggest to "&suggest=" & filename
      set the_file to ""
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
   on error e
      tell me to activate
      display dialog e
   end try
end handle_string


-------------------------------------------------------------------
--Handlers
-------------------------------------------------------------------

on dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
   set theDate to (do shell script "date '+%Y-%m-%d'")
   set pathFolder to ("Shared_Files:" & theDate & ":")
   
   --replace spaces in filename with underscores
   set newfilename to replace_chars(filename, " ", "_")
   
   set thedupcheck to publicfolder & pathFolder & newfilename
   if theformat = "folder" then
      set thedupcheck to thedupcheck & ".zip"
   end if
   tell me to activate
   
   tell application "Finder" to if not (exists (POSIX path of thedupcheck) as POSIX file) then
      --Changed Lines******************************************************   
      set thedecision to my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   else
      tell me to activate
      set thedisplay to display dialog "An item with the name \"" & newfilename & "\" already exists in the destination" buttons {"Cancel ", "Rename", "Replace"} default button "Replace"
      
      if button returned of thedisplay is "Replace" then
         my processreplace(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
      else if button returned of thedisplay is "Rename" then
         my processrename(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
      else
         return "Canceled"
         
      end if
   end if
end dupcheck

on processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   growlRegister()
   set thecmd to "mkdir -p '" & (POSIX path of (publicfolder & pathFolder)) & "'"
   do shell script thecmd
   if theformat = "file" then
      set thecmd to "cp '" & (POSIX path of the_file) & "' '" & (POSIX path of (publicfolder & pathFolder & newfilename)) & "'"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
      
   else if theformat = "folder" then
      set thecmd to "zip -r '" & (POSIX path of (publicfolder & pathFolder)) & newfilename & "' '" & (POSIX path of the_file) & "'"
      set newfilename to newfilename & ".zip"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
      
   else if theformat = "filerename" then
      set thecmd to "cp '" & (POSIX path of the_file) & "' '" & (POSIX path of (publicfolder & pathFolder & newfilename)) & "'"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
   else
      set filepath to publicfolder & pathFolder & newfilename
      set thecmd to "screencapture -i -t " & theformat & " '" & (POSIX path of filepath) & "'"
      do shell script thecmd
      growlNotify("Uploading screenshot ", newfilename)
      
   end if
   my processurl(pathFolder, newfilename, dropboxID)
   
   
end processitem

on processreplace(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   set filepath to publicfolder & pathFolder & newfilename
   if theformat = "folder" then
      set filepath to filepath & ".zip"
   end if
   set qfilepath to quoted form of (POSIX path of filepath)
   do shell script "rm -r " & qfilepath
   my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
end processreplace

on processrename(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   repeat
      set AppleScript's text item delimiters to "."
      set theonlyname to text items 1 thru -2 of newfilename
      set filenameextension to last text item of newfilename
      set AppleScript's text item delimiters to ""
      tell me to activate
      set newfilename to text returned of (display dialog "Enter the new name: (This dialog box will reappear if an item with the new name you specified also exists in the destination folder)" default answer theonlyname)
      if theformat is not equal to "folder" then
         set newfilename to newfilename & "." & filenameextension
      end if
      set thenewcheck to publicfolder & pathFolder & newfilename
      
      if theformat = "file" then set theformat to "filerename"
      
      tell application "Finder" to if not (exists (POSIX path of thenewcheck) as POSIX file) then
         my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
         exit repeat
      end if
   end repeat
end processrename

on processurl(pathFolder, filename, dropboxID)
   set theurl to "http://dl.dropbox.com/u/" & dropboxID & (POSIX path of pathFolder) & replace_chars(filename, " ", "%20")
   set the clipboard to theurl
   tell application "LaunchBar"
      set selection as text to theurl
      activate
   end tell
end processurl

on replace_chars(this_text, search_string, replacement_string)
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to ""
   return this_text
end replace_chars

-- additional scripting for Growlnotification
using terms from application "GrowlHelperApp"
   on growlRegister()
      tell application "GrowlHelperApp"
         register as application "Share with Dropbox" all notifications {"Alert"} default notifications {"Alert"} icon of application "Dropbox.app"
      end tell
   end growlRegister
   on growlNotify(grrTitle, grrDescription)
      tell application "GrowlHelperApp"
         notify with name "Alert" title grrTitle description grrDescription application name "Share with Dropbox"
      end tell
   end growlNotify
end using terms from

teedoff087
Posts: 14
Joined: Wed Sep 08, 2010 8:43 pm

Re: Screen shots and files sharing with Dropbox

Post by teedoff087 » Mon Mar 07, 2011 3:47 am

ccjensen wrote:My version. I don't like to use url shorteners, so removed that.
Added the folder format:
~/Dropbox/Public/Shared_Files/2010-12-01/filename.jpg

It only checks for duplicates within the same folder, and it replaces spaces file/folder names with underscores (except in the case where the user requests to rename).
It does screenshots as "screenshot_19-22-36.png"

Code: Select all

--Based upon https://github.com/aristidesfl/launchbar-scripts/blob/master/Share%20Dropbox.applescript

--================================== Modify Here =========================================--

property dropboxID : 123456 --> Replace this number with your dropbox ID

--================================== Modify Here =========================================--

--Usages:
--1. To share a file/folder, select it and send it to this action
--2. To share a screenshot select this action and press return
--3. To share a screenshot with a name, selecte this action, press space, enter a name and press return

on run
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      tell application "LaunchBar" to hide
      
      set theTime to (do shell script "date '+%H-%M-%S'")
      set theformat to "png"
      set filename to "screenshot_" & theTime & "." & theformat
      set the_file to ""
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
end run

on open (the_file)
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      
      tell application "LaunchBar" to hide
      try
         set text item delimiters to ":"
         set filename to last text item of (the_file as text)
         set theformat to "file"
         
         if filename = "" then
            set filename to text item ((count of text items of (the_file as text)) - 1) of (the_file as text)
            set theformat to "folder"
            
         end if
         set suggest to "&suggest=" & filename
         set text item delimiters to ""
      on error
         set text item delimiters to ""
      end try
      
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
   
   
end open

on handle_string(theText)
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      
      tell application "LaunchBar" to hide
      
      set AppleScript's text item delimiters to ","
      set filename to first text item of theText
      set theformat to false
      try
         set theformat to text 2 thru -1 of second text item of theText
      end try
      if theformat is false then set theformat to "png"
      set AppleScript's text item delimiters to ""
      set filename to filename & "." & theformat as text
      set suggest to "&suggest=" & filename
      set the_file to ""
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
   on error e
      tell me to activate
      display dialog e
   end try
end handle_string


-------------------------------------------------------------------
--Handlers
-------------------------------------------------------------------

on dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
   set theDate to (do shell script "date '+%Y-%m-%d'")
   set pathFolder to ("Shared_Files:" & theDate & ":")
   
   --replace spaces in filename with underscores
   set newfilename to replace_chars(filename, " ", "_")
   
   set thedupcheck to publicfolder & pathFolder & newfilename
   if theformat = "folder" then
      set thedupcheck to thedupcheck & ".zip"
   end if
   tell me to activate
   
   tell application "Finder" to if not (exists (POSIX path of thedupcheck) as POSIX file) then
      --Changed Lines******************************************************   
      set thedecision to my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   else
      tell me to activate
      set thedisplay to display dialog "An item with the name \"" & newfilename & "\" already exists in the destination" buttons {"Cancel ", "Rename", "Replace"} default button "Replace"
      
      if button returned of thedisplay is "Replace" then
         my processreplace(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
      else if button returned of thedisplay is "Rename" then
         my processrename(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
      else
         return "Canceled"
         
      end if
   end if
end dupcheck

on processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   growlRegister()
   set thecmd to "mkdir -p '" & (POSIX path of (publicfolder & pathFolder)) & "'"
   do shell script thecmd
   if theformat = "file" then
      set thecmd to "cp '" & (POSIX path of the_file) & "' '" & (POSIX path of (publicfolder & pathFolder & newfilename)) & "'"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
      
   else if theformat = "folder" then
      set thecmd to "zip -r '" & (POSIX path of (publicfolder & pathFolder)) & newfilename & "' '" & (POSIX path of the_file) & "'"
      set newfilename to newfilename & ".zip"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
      
   else if theformat = "filerename" then
      set thecmd to "cp '" & (POSIX path of the_file) & "' '" & (POSIX path of (publicfolder & pathFolder & newfilename)) & "'"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
   else
      set filepath to publicfolder & pathFolder & newfilename
      set thecmd to "screencapture -i -t " & theformat & " '" & (POSIX path of filepath) & "'"
      do shell script thecmd
      growlNotify("Uploading screenshot ", newfilename)
      
   end if
   my processurl(pathFolder, newfilename, dropboxID)
   
   
end processitem

on processreplace(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   set filepath to publicfolder & pathFolder & newfilename
   if theformat = "folder" then
      set filepath to filepath & ".zip"
   end if
   set qfilepath to quoted form of (POSIX path of filepath)
   do shell script "rm -r " & qfilepath
   my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
end processreplace

on processrename(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   repeat
      set AppleScript's text item delimiters to "."
      set theonlyname to text items 1 thru -2 of newfilename
      set filenameextension to last text item of newfilename
      set AppleScript's text item delimiters to ""
      tell me to activate
      set newfilename to text returned of (display dialog "Enter the new name: (This dialog box will reappear if an item with the new name you specified also exists in the destination folder)" default answer theonlyname)
      if theformat is not equal to "folder" then
         set newfilename to newfilename & "." & filenameextension
      end if
      set thenewcheck to publicfolder & pathFolder & newfilename
      
      if theformat = "file" then set theformat to "filerename"
      
      tell application "Finder" to if not (exists (POSIX path of thenewcheck) as POSIX file) then
         my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
         exit repeat
      end if
   end repeat
end processrename

on processurl(pathFolder, filename, dropboxID)
   set theurl to "http://dl.dropbox.com/u/" & dropboxID & (POSIX path of pathFolder) & replace_chars(filename, " ", "%20")
   set the clipboard to theurl
   tell application "LaunchBar"
      set selection as text to theurl
      activate
   end tell
end processurl

on replace_chars(this_text, search_string, replacement_string)
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to ""
   return this_text
end replace_chars

-- additional scripting for Growlnotification
using terms from application "GrowlHelperApp"
   on growlRegister()
      tell application "GrowlHelperApp"
         register as application "Share with Dropbox" all notifications {"Alert"} default notifications {"Alert"} icon of application "Dropbox.app"
      end tell
   end growlRegister
   on growlNotify(grrTitle, grrDescription)
      tell application "GrowlHelperApp"
         notify with name "Alert" title grrTitle description grrDescription application name "Share with Dropbox"
      end tell
   end growlNotify
end using terms from

LIKE! Thanks. Works great.

sjk
Wizard
Wizard
Posts: 315
Joined: Thu Sep 13, 2007 9:46 pm
Location: Eugene
Contact:

Re: Screen shots and files sharing with Dropbox

Post by sjk » Mon Mar 07, 2011 5:27 am

ccjensen wrote:I don't like to use url shorteners

Thank you!

keitofu
Posts: 18
Joined: Tue Dec 01, 2009 10:03 am

Re: Screen shots and files sharing with Dropbox

Post by keitofu » Mon May 30, 2011 11:04 am

Thanks for the script, I was wondering if there was a way to do that :)
I just changed it : I did not want the script to make another directory in the "public" so I adapted it a bit.

Thanks for all !

Was
Rank 2
Rank 2
Posts: 70
Joined: Wed Jan 13, 2010 2:27 am

Re: Screen shots and files sharing with Dropbox

Post by Was » Sat Oct 13, 2012 6:43 pm

Can anyone update this great script to work with the newer version of Growl available on the appstore, if that's possible?

ccjensen wrote:My version. I don't like to use url shorteners, so removed that.
Added the folder format:
~/Dropbox/Public/Shared_Files/2010-12-01/filename.jpg

It only checks for duplicates within the same folder, and it replaces spaces file/folder names with underscores (except in the case where the user requests to rename).
It does screenshots as "screenshot_19-22-36.png"

Code: Select all

--Based upon https://github.com/aristidesfl/launchbar-scripts/blob/master/Share%20Dropbox.applescript

--================================== Modify Here =========================================--

property dropboxID : 123456 --> Replace this number with your dropbox ID

--================================== Modify Here =========================================--

--Usages:
--1. To share a file/folder, select it and send it to this action
--2. To share a screenshot select this action and press return
--3. To share a screenshot with a name, selecte this action, press space, enter a name and press return

on run
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      tell application "LaunchBar" to hide
      
      set theTime to (do shell script "date '+%H-%M-%S'")
      set theformat to "png"
      set filename to "screenshot_" & theTime & "." & theformat
      set the_file to ""
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
end run

on open (the_file)
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      
      tell application "LaunchBar" to hide
      try
         set text item delimiters to ":"
         set filename to last text item of (the_file as text)
         set theformat to "file"
         
         if filename = "" then
            set filename to text item ((count of text items of (the_file as text)) - 1) of (the_file as text)
            set theformat to "folder"
            
         end if
         set suggest to "&suggest=" & filename
         set text item delimiters to ""
      on error
         set text item delimiters to ""
      end try
      
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
      
   on error e
      tell me to activate
      display dialog e
   end try
   
   
end open

on handle_string(theText)
   try
      if application "Dropbox" is not running then launch application "Dropbox"
      set publicfolder to {path to home folder as string, "Dropbox:Public:"} as string
      
      tell application "LaunchBar" to hide
      
      set AppleScript's text item delimiters to ","
      set filename to first text item of theText
      set theformat to false
      try
         set theformat to text 2 thru -1 of second text item of theText
      end try
      if theformat is false then set theformat to "png"
      set AppleScript's text item delimiters to ""
      set filename to filename & "." & theformat as text
      set suggest to "&suggest=" & filename
      set the_file to ""
      set thecmd to my dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
      
   on error e
      tell me to activate
      display dialog e
   end try
end handle_string


-------------------------------------------------------------------
--Handlers
-------------------------------------------------------------------

on dupcheck(filename, publicfolder, theformat, dropboxID, the_file)
   set theDate to (do shell script "date '+%Y-%m-%d'")
   set pathFolder to ("Shared_Files:" & theDate & ":")
   
   --replace spaces in filename with underscores
   set newfilename to replace_chars(filename, " ", "_")
   
   set thedupcheck to publicfolder & pathFolder & newfilename
   if theformat = "folder" then
      set thedupcheck to thedupcheck & ".zip"
   end if
   tell me to activate
   
   tell application "Finder" to if not (exists (POSIX path of thedupcheck) as POSIX file) then
      --Changed Lines******************************************************   
      set thedecision to my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   else
      tell me to activate
      set thedisplay to display dialog "An item with the name \"" & newfilename & "\" already exists in the destination" buttons {"Cancel ", "Rename", "Replace"} default button "Replace"
      
      if button returned of thedisplay is "Replace" then
         my processreplace(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
      else if button returned of thedisplay is "Rename" then
         my processrename(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
      else
         return "Canceled"
         
      end if
   end if
end dupcheck

on processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   growlRegister()
   set thecmd to "mkdir -p '" & (POSIX path of (publicfolder & pathFolder)) & "'"
   do shell script thecmd
   if theformat = "file" then
      set thecmd to "cp '" & (POSIX path of the_file) & "' '" & (POSIX path of (publicfolder & pathFolder & newfilename)) & "'"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
      
   else if theformat = "folder" then
      set thecmd to "zip -r '" & (POSIX path of (publicfolder & pathFolder)) & newfilename & "' '" & (POSIX path of the_file) & "'"
      set newfilename to newfilename & ".zip"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
      
   else if theformat = "filerename" then
      set thecmd to "cp '" & (POSIX path of the_file) & "' '" & (POSIX path of (publicfolder & pathFolder & newfilename)) & "'"
      do shell script thecmd
      growlNotify("Uploading file ", newfilename)
   else
      set filepath to publicfolder & pathFolder & newfilename
      set thecmd to "screencapture -i -t " & theformat & " '" & (POSIX path of filepath) & "'"
      do shell script thecmd
      growlNotify("Uploading screenshot ", newfilename)
      
   end if
   my processurl(pathFolder, newfilename, dropboxID)
   
   
end processitem

on processreplace(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   set filepath to publicfolder & pathFolder & newfilename
   if theformat = "folder" then
      set filepath to filepath & ".zip"
   end if
   set qfilepath to quoted form of (POSIX path of filepath)
   do shell script "rm -r " & qfilepath
   my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
end processreplace

on processrename(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
   repeat
      set AppleScript's text item delimiters to "."
      set theonlyname to text items 1 thru -2 of newfilename
      set filenameextension to last text item of newfilename
      set AppleScript's text item delimiters to ""
      tell me to activate
      set newfilename to text returned of (display dialog "Enter the new name: (This dialog box will reappear if an item with the new name you specified also exists in the destination folder)" default answer theonlyname)
      if theformat is not equal to "folder" then
         set newfilename to newfilename & "." & filenameextension
      end if
      set thenewcheck to publicfolder & pathFolder & newfilename
      
      if theformat = "file" then set theformat to "filerename"
      
      tell application "Finder" to if not (exists (POSIX path of thenewcheck) as POSIX file) then
         my processitem(filename, newfilename, publicfolder, pathFolder, theformat, dropboxID, the_file)
         exit repeat
      end if
   end repeat
end processrename

on processurl(pathFolder, filename, dropboxID)
   set theurl to "http://dl.dropbox.com/u/" & dropboxID & (POSIX path of pathFolder) & replace_chars(filename, " ", "%20")
   set the clipboard to theurl
   tell application "LaunchBar"
      set selection as text to theurl
      activate
   end tell
end processurl

on replace_chars(this_text, search_string, replacement_string)
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to ""
   return this_text
end replace_chars

-- additional scripting for Growlnotification
using terms from application "GrowlHelperApp"
   on growlRegister()
      tell application "GrowlHelperApp"
         register as application "Share with Dropbox" all notifications {"Alert"} default notifications {"Alert"} icon of application "Dropbox.app"
      end tell
   end growlRegister
   on growlNotify(grrTitle, grrDescription)
      tell application "GrowlHelperApp"
         notify with name "Alert" title grrTitle description grrDescription application name "Share with Dropbox"
      end tell
   end growlNotify
end using terms from

aristidesfl
Rank 3
Rank 3
Posts: 120
Joined: Sat Feb 27, 2010 12:54 am

Re: Screen shots and files sharing with Dropbox

Post by aristidesfl » Sat Oct 13, 2012 9:02 pm

I'm using growl 1.4 and this one is working: https://github.com/aristidesfl/launchba ... pplescript
Which version are you using?

Post Reply