Copy Dropbox Link Within Finder
Title
Copy Dropbox Link Within Finder
What do you expect to happen when you run the script/macro?
Hi!
I had this script that would copy the dropbox link within finder of the selcted file/folder.
I updated my OS and now it doesn't work.
Help!!
Are you seeing an error?
What happens when you run this script?
It doesn't work. Soundflow gives me an error
How were you running this script?
I used a keyboard shortcut within the target app
How important is this issue to you?
3
Details
{ "inputExpected": "Hi!\n\nI had this script that would copy the dropbox link within finder of the selcted file/folder.\n\nI updated my OS and now it doesn't work.\n\nHelp!!", "inputIsError": true, "inputWhatHappens": "It doesn't work. Soundflow gives me an error", "inputHowRun": { "key": "-Mpfwh4RkPLb2LPwjePT", "title": "I used a keyboard shortcut within the target app" }, "inputImportance": 3, "inputTitle": "Copy Dropbox Link Within Finder" }
Source
sf.ui.finder.appActivate();
const popupMenu = sf.ui.finder.mainWindow.children.whoseRole.is("AXToolbar").first.groups.allItems[4].children.whoseRole.is("AXMenuButton").whoseTitle.is("").first.popupMenuOpenFromElement().popupMenu;
popupMenu.menuClickPopupMenu({
menuPath: ["Copy Dropbox Link"],
});
Links
User UID: V1j0aAqXguStBYYHVLNaRpbeV4V2
Feedback Key: sffeedback:V1j0aAqXguStBYYHVLNaRpbeV4V2:-NZ2w2IEgl6pjVMPLxPY
- MMatthew Bronleewe @Matthew_Bronleewe
Were you able to update this script? I'm curious if you found a solution!
- YIn reply toyianniap⬆:yianniap @yianniap
Unfortunately not. I never figured it out
- In reply toyianniap⬆:Raphael Sepulveda @raphaelsepulveda2024-01-31 21:14:38.816Z
@yianniap, @Matthew_Bronleewe,
Hey guys, give this a shot. Tested in Ventura 13.6.3.
sf.ui.finder.appActivate(); const popupMenu = sf.ui.finder.focusedWindow.children.whoseRole.is("AXToolbar").first .children.whoseRole.is("AXMenuButton").whoseDescription.is("Dropbox").first .children.whoseRole.is("AXMenuButton").first; popupMenu.popupMenuSelect({ relativePosition: { x: 20, y: 15 }, menuPath: ["Copy Dropbox link"], });
- MIn reply toyianniap⬆:Matthew Bronleewe @Matthew_Bronleewe
Hey @raphaelsepulveda ! Just tried running the script and this happened:
31.01.2024 16:07:49.47 [Backend]: !! Command Error: Copy Dropbox Link [user:default:cls2c7jxw002nos10y6cetbip]:
Could not open popup menu (Copy Dropbox Link: Line 8)
popupMenu.open.fromElement requires an element - MIn reply toyianniap⬆:Matthew Bronleewe @Matthew_Bronleewe
Just to note, the steps I took: I opened the Dropbox folder on my Mac, then selected an already-uploaded file, then hit the SoundFlow button...
- MIn reply toyianniap⬆:Matthew Bronleewe @Matthew_Bronleewe
Also, just to clarify what I'm trying to do, I'd like to control-click on a file within the dropbox folder that lives on my Mac, and then choose "Copy Dropbox link". (I'd also like to add a second function that chooses "Make online-only" within that same menu.) Thanks!
- TIn reply toyianniap⬆:Thomas Gloor @Thomas_Gloor
@raphaelsepulveda I'm getting the same error as @Matthew_Bronleewe
It's like SF doesn't see the finder window. I used this bit of code, with a folder that resides within my DropBox selected in the Finder.
sf.ui.finder.appActivate() const popupMenu = sf.ui.finder.focusedWindow.children.whoseRole.is("AXToolbar").first .children.whoseRole.is("AXMenuButton").whoseDescription.is("Dropbox").first .children.whoseRole.is("AXMenuButton").first; popupMenu.popupMenuSelect({ relativePosition: { x: 20, y: 15 }, menuPath: ["Copy Dropbox link"], }); let dbLink = sf.clipboard.getText().text alert(dbLink)
Any idea?
- MIn reply toyianniap⬆:Matthew Bronleewe @Matthew_Bronleewe
Hey that worked for me! It does a little SoundFlow popup box at the end with the name of the link, which is cool, but if I didn't want that popup, how would the code change? Also wondering about a script to "Make online-only" (same menu as "Copy Dropbox link"). Thanks for the help! I'm so new to this!
- MIn reply toyianniap⬆:Matthew Bronleewe @Matthew_Bronleewe
Actually, what would be really cool is some kind of toggle for "Make online-only" and "Make available offline". One button that you could push and the script would "see" if the file is available offline or online-only and switch it to the opposite. Some kind of "if, then" scenario!
- In reply toyianniap⬆:Raphael Sepulveda @raphaelsepulveda2024-02-03 04:49:25.079Z
@Matthew_Bronleewe, @Thomas_Gloor, hey guys, just want to clarify what this script does.
It will find the Dropbox button that lives in the toolbar of any Finder window, press it and select the "Copy Dropbox link" option from the popup menu that appears. As long as there is a file selected in Finder, it should work. Here it is in action:
Thomas, if you're getting a "requires an element" error, do you have the Dropbox button on your Finder window?
I gotta ask since it is possible to set up a Finder window to hide the toolbar completely, leaving us with no Dropbox button to interact with.Hey that worked for me!
Matthew, the script Thomas posted is the same one I originally posted but with the addition of the last two lines, which are just for logging the contents of the clipboard. That means that the script did end up working on your system after all. Do you remember what changed from the first time you tried it?
I'd also like to add a second function that chooses "Make online-only" within that same menu
All you have to do is change the menu path to whichever menu item you want to select, that will be line 10. Here is how you would change it for "Make online-only":
menuPath: ["Make online-only"],
- TThomas Gloor @Thomas_Gloor
Thank you! Yes I do, which makes me think it might be an OSX issue on my side!
I’ll fiddle with it today and post here to let you know!
- TThomas Gloor @Thomas_Gloor
@raphaelsepulveda
Still not workin. It behaves as if it doesn’t see the finder window or the button.
Do you have an idea?Raphael Sepulveda @raphaelsepulveda2024-02-04 02:18:47.773Z
@Thomas_Gloor, could you take a short video to see if I can spot any clues?
- TThomas Gloor @Thomas_Gloor
I did some digging and managed to solve the problem by "Picking" the Dropbox button again. I then had problems to store the link in a variable, but solved it by using
sf.clipboard.waitForText()
.I made it into a nifty little function. It checks if the wanted path is a part of Dropbox. If not, the user has to pick a valid path in the window that the script opened. If the path is a part of DropBox, it goes to the wanted path in the Finder, clears the clipboard, get's the link, closes the Finder window and returns the link.
Here's the function.
let path = "YOUR PATH HERE" let dbLink = getDropBoxLink({ path: path }) alert(dbLink) /** @param {Object} options - Options object. {string} options.path - The path of the file or folder.*/ function getDropBoxLink({ path }) { let finder = sf.ui.finder finder.appActivate() sf.clipboard.clear() if (!(/dropbox/i).test(path)) { finder.menuClick({ menuPath: ["File", "New Finder Window"] }) finder.appActivate() alert("The path isn't a part of Dropbox, please select a valid path and press OK") path = finder.selectedPaths } else { sf.appleScript.finder.select(path); finder.appActivateMainWindow(); finder.mainWindow.splitGroups.first.elementWaitFor({ waitType: "Appear" }) sf.wait({ intervalMs: 500 }) } let dropbBoxButton = finder.mainWindow.children.whoseRole.is("AXToolbar").first.children.whoseRole.is("AXMenuButton").whoseTitle.is("Dropbox").first.children.whoseRole.is("AXMenuButton").first dropbBoxButton.popupMenuSelect({ menuPath: ["Copy Dropbox link"] }) sf.wait({ intervalMs: 500 }) sf.clipboard.waitForText({intervalMs: 2000}) finder.menuClick({ menuPath: ["File", "Close Window"] }) return sf.clipboard.getText().text }
Raphael Sepulveda @raphaelsepulveda2024-02-04 18:29:20.247Z
Sweet!
- TThomas Gloor @Thomas_Gloor
@raphaelsepulveda thanks man!
Any idea how to ensure that the DB button is displayed? I tried to menuClick Windows-> Zoom, but it doesn’t really cut it.
Raphael Sepulveda @raphaelsepulveda2024-02-04 20:30:53.291Z2024-02-04 22:33:52.330Z
@Thomas_Gloor, this one is a bit tricky since there could be several reasons why the Dropbox button wouldn't show, but I will cover the first two most common situations I can think of—the toolbar is hidden and/or the window is too small to show all toolbar options.
I've implemented the solutions into your script:
const path = "YOUR PATH HERE"; /** @param {Object} options - Options object. {string} options.path - The path of the file or folder.*/ function getDropBoxLink({ path }) { const finder = sf.ui.finder; finder.appActivate(); sf.clipboard.clear(); if (!(/dropbox/i).test(path)) { finder.menuClick({ menuPath: ["File", "New Finder Window"] }); finder.appActivate(); alert("The path isn't a part of Dropbox, please select a valid path and press OK"); sf.ui.finder.mainWindow.invalidate(); path = finder.selectedPaths; } else { sf.appleScript.finder.select(path); finder.appActivateMainWindow(); finder.mainWindow.splitGroups.first.elementWaitFor({ waitType: "Appear" }); sf.wait({ intervalMs: 500 }); sf.ui.finder.mainWindow.invalidate(); } // Ensure toolbar exists if (!sf.ui.finder.getMenuItem("View", "Hide Toolbar").exists) { sf.ui.finder.menuClick({ menuPath: ["View", "Show Toolbar"] }) sf.ui.finder.mainWindow.children.whoseRole.is("AXToolbar").first.elementWaitFor(); sf.ui.finder.mainWindow.invalidate(); } const dropboxButton = sf.ui.finder.mainWindow.children.whoseRole.is("AXToolbar").first .children.whoseRole.is("AXMenuButton").whoseDescription.is("Dropbox").first .children.whoseRole.is("AXMenuButton").first; // Button that appears when a Finder window is too small to house all toolbar options const overflowButton = sf.ui.finder.mainWindow.children.whoseRole.is("AXToolbar").first.getElement("AXOverflowButton"); // If the Dropbox button doesn't exist but the Overflow one those... if (!dropboxButton.exists && overflowButton.exists) { // Select "Copy Dropbox link" from the Overflow button overflowButton.popupMenuSelect({ relativePosition: { x: 10, y: 10 }, // Required in some systems menuPath: ["Dropbox", "Copy Dropbox link"] }); } else { dropboxButton.popupMenuSelect({ // relativePosition: { x: 20, y: 15 }, // Required in some systems menuPath: ["Copy Dropbox link"] }); } sf.wait({ intervalMs: 500 }); sf.clipboard.waitForText({ intervalMs: 2000 }); finder.menuClick({ menuPath: ["File", "Close Window"] }); return sf.clipboard.getText().text; } const dbLink = getDropBoxLink({ path }); alert(dbLink);
Here's the logic:
- If the toolbar is hidden, it will show it.
- If the Dropbox button doesn't exist but the overflow one does (the window is too small), select the "Copy Dropbox link" option through it.
- If the Dropbox button exists, select the "Copy Dropbox link" through it.
Some final notes. A difference between our systems is that for this to work in mine I need to put in some
relativePosition
values when callingpopupMenuSelect
on these buttons, while in yours that doesn't seem to be necessary. If the script doesn't work at first try removing therelativeValue
property on line 43:relativePosition: { x: 10, y: 10 }
As I said somewhere in this thread, automating this Dropbox integration is pretty fragile but hopefully this all ends up working on your end.
- TThomas Gloor @Thomas_Gloor
Awesome! Thank you @raphaelsepulveda
Just one question. The return at line 47 won’t yield the exact result as my initial function right (get the link into a variable).
I can just make it work by making your if an if else with lines 50-53 as the else and have 54-> end afterwards. Am I right?
Raphael Sepulveda @raphaelsepulveda2024-02-04 22:34:39.657Z
Ah, my bad! You're correct. Just edited the previous script to fix that. Good catch!
- TThomas Gloor @Thomas_Gloor
Oh that’s nice! I’d have done it :)
Thank you yet again!
- TThomas Gloor @Thomas_Gloor
Hey @raphaelsepulveda,
Funny, but your script didn't work, be it with or without the
relativePostition
. I basically adapted mine copying yours for it to work!Raphael Sepulveda @raphaelsepulveda2024-02-05 13:42:53.052Z
Oh man, I’m just glad you’re comfortable enough with the code to troubleshoot and do the modifications yourself.
This seems to be very system specific.
- TThomas Gloor @Thomas_Gloor
Haha I learned a lot, mostly from you guys!
Yeah it appears to be very hard to stabilize and I can't see what's so different from your system...
- MIn reply toyianniap⬆:Matthew Bronleewe @Matthew_Bronleewe
Ok, yes, this is all very helpful! I think one problem I had was that the Dropbox button in the toolbar was "hiding", so I repositioned it to be more readily available.
I ended up using two scripts, one for copying the Dropbox link, and one for making it online-only.
What would really be useful is if I could have a button that would toggle between "Make online-only" and "Make available offline". How might that be possible?
Raphael Sepulveda @raphaelsepulveda2024-02-04 02:35:58.189Z
Mmm, the Dropbox integration into Finder is pretty limited for our automation purposes.
For this to work we would need a way to know what the current Dropbox state of the selected file is. Usually, menus change their items to reflect that. For example, if the file is already "online" then it would show just the "Make available offline" option and vice versa. That doesn't happen here, unfortunately—it shows us both options.
I know that every file has a Dropbox status icon next to it that displays its online/offline status, so it is technically possible to use that to make it happen. I'm currently tied up working on other scripts but hopefully another one of our fellow coders can dive into this one 🙏🏼
- MIn reply toyianniap⬆:Matthew Bronleewe @Matthew_Bronleewe
Also, are there any resources for getting to understand the scripting better? I feel like I'm getting to understand some bits of code, but I'd really love to be able to understand more!
Raphael Sepulveda @raphaelsepulveda2024-02-04 02:42:55.415Z
Yeah! A great place to start is the "Scripting - dive deeper" section on the following page: https://soundflow.org/docs/how-to/custom-commands/using-code-completion
After that, it would be a matter of getting familiar with the Soundflow API (through the SF editor) and trying out what everything does. This forum is the best resource there is. If you want to find examples of what a method does, you can search it here and find dozens of use cases 👌🏼