-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShare Dropbox.applescript
253 lines (201 loc) · 8.36 KB
/
Share Dropbox.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
--================================== Modify Here =========================================--
property dropboxID : 0000000 --> 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 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
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 ifolder to {path to home folder as string, "Dropbox:Public:"} as string
tell application "LaunchBar" to hide
try
--set text item delimiters to "."
--set theextension to last text item of (the_file as text)
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
--display dialog the_file as text
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
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 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
tell me to activate
display dialog e
end try
end handle_string
-------------------------------------------------------------------
--Handlers
-------------------------------------------------------------------
on dupcheck(thename, ifolder, theformat, dropboxID, the_file)
if theformat = "folder" then
set finalname to thename & ".zip"
else
set finalname to thename
end if
set thedupcheck to ifolder & finalname
if ifolder is in (the_file as text) then
processurl(finalname, dropboxID)
else
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 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 = "folder" then
--set text item delimiters to "."
--set theextension to "" --last text item of (thename as text)
set thefileLess1 to text 1 thru -2 of POSIX path of the_file
set theReversedFileName to (reverse of (characters of thefileLess1)) as string
set theOffset to offset of "/" in theReversedFileName
set thePrefix to (reverse of (characters (theOffset + 1) thru -1 of theReversedFileName)) as string
set theSuffix to (reverse of (characters 1 thru (theOffset - 1) of theReversedFileName)) as string
--display dialog theSuffix as text
set shellscript to "cd '" & thePrefix & "/' ; zip -r '" & (POSIX path of ifolder) & thename & ".zip' '" & (theSuffix) & "/'"
-- display dialog the_file as text
--display dialog shellscript
do shell script shellscript
set thename to thename & ".zip"
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
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 curlCMD to "curl -s https://www.googleapis.com/urlshortener/v1/url -H 'Content-Type: application/json' -d '{\"longUrl\": \"" & theurl & "\"}' | egrep -o 'http://goo.gl/[^\\\"]*'"
--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 "Growl"
on growlRegister()
tell application "Growl"
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 "Growl"
notify with name "Alert" title grrTitle description grrDescription application name "Share with Dropbox"
end tell
end growlNotify
end using terms from