Monday, July 22, 2019

#1 2017-02-12 07:19:57 pm

Beeman
Member
Registered: 2006-03-07
Posts: 72

DropBox and a copy link

hello all
I am trying to figure out how to get a link generated by DropBox when you click on "copy link" into a variable. I am trying to build a script that will take the DropBox link and create an email with the link in the body of the email.

I can do the email part, but can't figure out how to get the link

thanks for any thoughts or help

Kevin

Browser: Safari 602.3.12
Operating System: Mac OS X (10.10)

Offline

 

#2 2017-02-13 10:39:12 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 411

Re: DropBox and a copy link

This is probably too much of a PITA, but one option is to use "do shell script" with CURL and use Dropbox's HTTP API.

https://www.dropbox.com/developers/docu … h_settings

However, it requires authentication:

https://www.dropbox.com/developers/docu … rom_oauth1

And the first time they request, Dropbox will ask for them to allow access to your app.

Seems like there must be a better way. Maybe through UI scripting if there's no direct path.

Dropbox has no Applescript dictionary, the command-line control for Dropbox doesn't work on OSX (it's only for Linux.) I'm not aware of a way to get Finder contextual menu items though terminal...

So other than a possible UI scripting option or just going ahead and using the API, I'm short on ideas.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#3 2017-02-13 12:12:49 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 411

Re: DropBox and a copy link

I took a quick look at UI scripting it, but I had no luck.

Applescript:

tell application "Finder"
   activate
   delay 1
end tell

tell application "System Events"
   tell application process "Finder"
       set theItem to text field 1 of UI element 1 of row 14 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Dropbox"
       tell theItem to perform action "AXShowMenu"
   end tell
end tell

This script does not return any error, but it also doesn't open the contextual menu, and I don't know why it doesn't work. I thought I could open the menu that way, then script selecting the item to copy the Dropbox link to the clipboard.

Even if this did work, you'd need scripting to ensure the window is open, in a consistent view, and then determine the "row" of your item in the Finder view.

I also took a quick look at the formatting of the Dropbox links, wondering if you could just construct them yourself from information you could get, but that didn't appear to be the case.

To me, it looks like the API is the best bet, although I'm afraid it's probably more programming than you were hoping for.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#4 2017-02-16 11:39:31 am

Beeman
Member
Registered: 2006-03-07
Posts: 72

Re: DropBox and a copy link

thank you so much for trying...

It does seem like too much programming. Maybe I will contact Dropbox and see if they are willing to help

I searched here and could find an answer. You would think this would have come up before

Kevin

Browser: Safari 602.3.12
Operating System: Mac OS X (10.10)

Offline

 

#5 2019-07-11 08:56:19 pm

aechadwick
Member
Registered: 2006-07-27
Posts: 39

Re: DropBox and a copy link

i wanted to do this exact same thing.

Here is my solution. I've been testing it for a couple days, and it works quite reliably. I am open to suggestions and improvements.

Let me know what you think.

Totally Easy Steps to get access token... (the google website changes sometimes, these are the steps right now today)

1. Log in to developer.dropbox.com (you don’t need a developer account, just login to dropbox like regular and go to this developer page)
2. Click on Create Apps
3. Choose an API: Dropbox
4. Choose the type of access (i use "Full Dropbox" but you do you)
5. Name your app (you will not be using the name in the AppleScript, so just name it something you will remember)
6. Generate Access Token. (Copy that, paste it into the script, and do not share it with anyone.)

I made a droplet...

those ridiculous \\\ are required to escape the escape \" that is required for the curl... that said, there's a LOT of double and single quotes and escaped characters in those commands--paste carefully and triple check the syntax.
replace [PUT ACCESS TOKEN HERE], [USERNAME], and of course change the /test/ directory to your desired path


Applescript:

on open some_items
   
   set theDropBoxBearerToken to "[PUT ACCESS TOKEN HERE]"
   
   repeat with this_item in some_items
       
       set TheSourceFile to (quoted form of POSIX path of this_item)
       
       tell application "Finder" to set theFilename to (the name of (this_item as alias) as string)
       
       set WhereTheFileGoes to "test/" & theFilename
       
       set WhereTheFileIsLocally to "/Users/[USERNAME]/Dropbox/test/" & theFilename --assuming a standard Dropbox install
       
       --REMOVE PRIOR (i often update-and-repost-files; if you don't, you can remove this.) (if there's no existing file, it just does nothing)
       do shell script "curl -X POST https://api.dropboxapi.com/2/files/delete_v2 --header \"Authorization: Bearer " & theDropBoxBearerToken & "\" --header \"Content-Type: application/json\" --data \"{\\\"path\\\": \\\"/" & WhereTheFileGoes & "\\\"}\""
       
       --UPLOAD CURRENT
       do shell script "curl -sX POST https://content.dropboxapi.com/2/files/upload --header \"Authorization: Bearer " & theDropBoxBearerToken & "\" --header \"Dropbox-API-Arg: {\\\"path\\\": \\\"/" & WhereTheFileGoes & "\\\",\\\"mode\\\": \\\"overwrite\\\",\\\"autorename\\\": false,\\\"mute\\\": false}\" --header \"Content-Type: application/octet-stream\" --data-binary @" & TheSourceFile
       
       --GET INFO
       set TheRawDropBoxInfo to {do shell script "curl -s -X POST https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings --header \"Authorization: Bearer " & theDropBoxBearerToken & "\" --header \"Content-Type: application/json\" --data \"{\\\"path\\\": \\\"/" & WhereTheFileGoes & "\\\",\\\"settings\\\": {\\\"requested_visibility\\\": \\\"public\\\"}}\""}
       
       --PARSE LINK FROM INFO
       set theDropBoxLink to {do shell script "grep -Eo 'https://www.dropbox.com(/[[:graph:]]*)?' <<< '" & TheRawDropBoxInfo & "' | cut -d\\\" -f1"}
       
       display dialog theDropBoxLink
       --do stuff here. my goal is: make email with attachment:WhereTheFileIsLocally and link:theDropBoxLink
       
   end repeat
   
end open

Last edited by aechadwick (2019-07-11 09:00:48 pm)


Filed under: cURL, Dropbox, Upload Link

Offline

 

#6 2019-07-11 09:49:12 pm

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 411

Re: DropBox and a copy link

Thanks, it's great to see some Applescript examples and instructions for interfacing with the Dropbox API.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

#7 2019-07-11 11:58:22 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 234

Re: DropBox and a copy link

Applescript:


set theDropboxFolder to (path to home folder as text) & "Dropbox:"
-- REPLACE HERE TESTING FILE WITH YOUR OWN REAL EXISTING FILE
set theFile to (theDropboxFolder & "USB_VLC_Player.workflow.zip") as alias

-- NOTE: Here I PROCESS FOR SIMPLITY ONLY 1 FILE
-- YOU CAN LIST ALL FILES AND FOLDERS OF "DROPBOX" folder
-- and process them USING REPEAT LOOP

tell application "Finder"
   -- BRING TO FRONT "DROPBOX" folder
   if front Finder window exists then
       set target of front Finder window to theDropboxFolder
   else
       open theDropboxFolder
   end if
   -- set property SELECTION of FINDER to processed file (or folder)
   set the selection to theFile
end tell

do shell script "printf %s \"\" | pbcopy" -- CLEAR THE CLIPBOARD

tell application "System Events"
   tell application process "Finder"
       -- RIGHT_CLICKING TO OPEN NEEDED MENU
       set _selection to value of attribute "AXFocusedUIElement"
       tell _selection to perform action "AXShowMenu"
       -- WAIT UNTIL NEEDED WINDOW BECOMES ACTIVE
       repeat until window "Dropbox" exists
           delay 0.1
       end repeat
       -- COPY LINK TO THE CLIPBOARD
       click menu item "Copy Dropbox Link" of menu 1 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Dropbox"
   end tell
end tell

-- WAIT UNTIL THE CLIPBOARD GETS the URL
set theURL to ""
repeat while (theURL = "")
   try
       delay 0.1
       set theURL to (the clipboard as text)
   end try
end repeat

Last edited by KniazidisR (2019-07-12 04:18:37 am)


macOS Mojave -- version 10.14.4
Safari -- version 12.1

Offline

 

#8 2019-07-12 08:07:09 am

t.spoon
Member
From:: BFE, Massachusetts
Registered: 2013-01-13
Posts: 411

Re: DropBox and a copy link

KniazidisR

Brilliant, thanks. I'd tried, and I know others had too, and we couldn't get that UI scripting to work.

I think your script will be a good example for other UI scripting issues I've had too.


Hackintosh built February, 2012 |  Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)