Quantcast
Channel: Objective Development Forums
Viewing all articles
Browse latest Browse all 4524

Re: Screen shots and files sharing with Dropbox

$
0
0
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"

--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

Viewing all articles
Browse latest Browse all 4524

Trending Articles