Box.com and copy link

I want to save te link I get from Box.com (when I click on copy link in finder) into a variable. And, then, with a little script I would create a mail and paste the link into te mail and send the mail. The laste step I have already.

I have had a look to the forum, and I found an example with Dropbox:
https://macscripter.net/viewtopic.php?id=45518

The e-mail part is not a problem, but copying the link from Box.com… Can anyone help me with that?

Thank in advance!

Amelie

On my machine this script does the job.

set the clipboard to ""
tell application "System Events" to tell process "Safari"
	set frontmost to true
	tell window 1
		class of UI elements --> {splitter group, button, button, button, group, button, group, toolbar}
		tell splitter group 1
			class of UI elements --> {splitter, tab}
			tell tab group 1
				class of UI elements --> {group} 
				tell group 1
					class of UI elements --> {group} 
					tell group 1
						class of UI elements --> {scroll area} 
						tell scroll area 1
							class of UI elements --> {UI element} 
							tell UI element 1
								class of UI elements --> {group, group, group, group, button, group, group, group}
								
								title of button 1
								-- tell group 1 to get class of UI elements --> {UI element}
								-- tell group 2 to get class of UI elements --> {UI element, group, button, pop up button, pop up button, pop up button, pop up button}
								-- tell group 3 to get class of UI elements --> {group, UI element, UI element, group, group}
								-- tell group 4 to get class of UI elements --> {button, group, group, group, pop up button, button, slider, button, button, button, UI element, table, UI element, table, group, tab, group}
								-- tell group 5 to get class of UI elements --> {group}
								-- tell group 6 to get class of UI elements --> {image, group}
								tell group 7
									-- class of UI elements --> {group}
									tell group 1
										-- class of UI elements --> {group, group}
										-- tell group 1 to get class of UI elements --> {}
										tell group 2
											-- class of UI elements --> {group, button, group, pop up button, splitter, static text, group, group, group, button, button, group, group}
											-- title of buttons --> {"", "Copy", ""}
											click button "Copy"
										end tell -- group 2
									end tell -- group 1
								end tell -- group 7
							end tell -- UI element 1
						end tell -- scroll area 1
					end tell -- group 1
				end tell -- group 1
			end tell -- tab group 1
		end tell -- splitter group 1
	end tell -- window 1
end tell -- System Events
set theLink to the clipboard

set theURL to ""
repeat while (theURL = "")
	try
		delay 0.1
		set theURL to (the clipboard as text)
	end try
end repeat

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 21 avril 2020 18:02:34

Can you please give me some more information about the script, I don’t understand what the script is doing.

On my computer, the script is not working. I get an error with the word ‘title’

How is the script selecting the file on my box. My box account is full of files, how do I select the file for which I need the link?

The original script was designed to click the Copy button when the dedicated pane is open.
I am unable to guess the structure of your datas in your BOX area.
In mine I have 3 folders +23 files (in two pages) at the first level
in the first of the 3 folders are 9 folders +23 files
In the first of these 9 folders are 3 folders and 169 files.

In my original message I edited the script enabling some instructions.
As is, it’s supposed to reach in the GUI the level where a button available here is unavailable for you.

Honestly I don’t see how to navigate in such structure without being in front of it.

I tried to navigate in the numerous level of the GUI and I hit a wall.
The compiler refuse to enter a given level in the hierarchy because too many tells are used
As far as I know, here is no way to break this wall.

set the clipboard to ""
tell application "System Events" to tell process "Safari"
	set frontmost to true
	tell window 1
		class of UI elements --> {splitter group, button, button, button, group, button, group, toolbar}
		tell splitter group 1 to tell tab group 1 to tell group 1 to tell group 1 to tell scroll area 1
			class of UI elements --> {UI element} 
			tell UI element 1
				class of UI elements --> {group, group, group, group, button, group, group, group}
				
				title of button 1 --> "Drop files on this page to upload them into this folder."
				(*
				-- disabled because too many tells are nested, the compiler refuse to apply
				tell group 1
					get class of UI elements --> {UI element}
					tell UI element 1
						get class of UI elements --> {static text}
					end tell
				end tell
				*)
				-- tell group 2 to get class of UI elements --> {UI element, group, button, pop up button, pop up button, pop up button, pop up button}
				-- tell group 3 to get class of UI elements --> {group, UI element, UI element, group, group}
				tell group 4
					get class of UI elements --> {button, group, group, group, pop up button, button, slider, button, button, button, UI element, table, UI element, table, group, tab, group}
					tell table 1
						get class of UI elements --> --> {row, row, row, column, group}
						tell group 1
							get class of UI elements --> {}
						end tell
						tell row 1
							get class of UI elements --> {UI element}
							tell UI element 1
								get class of UI elements --> {image, group, button, group, group, group, pop up button}
								tell group 1
									get class of UI elements --> {group}
									tell group 1
										get class of UI elements --> {UI element}
										-- disabled because it fails to compile with warning : 
										-- Des instructions « Tell » sont emboîtées trop profondément.
										(*
										tell UI element 1 
											get class of UI elements --> {Static Text}
											-- get the name of the folder
										 	value of Static Text 1 --> public_YK
										end tell
										*)
									end tell
								end tell
								-- infos about the folder
								tell group 2 to get value of static text 1 --> "Dec 30, 2019 by KoenigYvanWalter"
								-- contents of the folder
								tell group 3 to get value of static text 1 --> "759 Files"
								tell group 4 to get class of UI elements --> {}
								get description of pop up button 1 --> "More Options"
								--click button 1 -- to reveal the pane in which we will clich "Copy"
							end tell
						end tell
						(*
										tell row 2
											get class of UI elements--> {UI element}
										end tell
										tell row 3
											get class of UI elements--> {UI element}
										end tell
										*)
					end tell
				end tell
				-- tell group 5 to get class of UI elements --> {group}
				-- tell group 6 to get class of UI elements --> {image, group}
				(*
								tell group 7
									-- class of UI elements --> {group}
									tell group 1
										-- class of UI elements --> {group, group}
										-- tell group 1 to get class of UI elements --> {}
										tell group 2
											-- class of UI elements --> {group, button, group, pop up button, splitter, static text, group, group, group, button, button, group, group}
											-- title of buttons --> {"", "Copy", ""}
											click button "Copy"
										end tell -- group 2
									end tell -- group 1
								end tell -- group 7
								*)
			end tell -- UI element 1
		end tell -- scroll area 1
	end tell -- window 1
end tell -- System Events

(*
set theURL to ""
repeat while (theURL = "")
	try
		delay 0.1
		set theURL to (the clipboard as text)
	end try
end repeat
*)

So I think that you must enter an other scheme.
Build a list of the files stored in your BOX area.
Grab by hand the links giving access to each file
Use a choose from list instruction to select the item to link
ask the script which is the link attached to the selected item.
Something like that:

set doubleList to {}
set end of doubleList to {"001 2_YK.zip", "https://app.box.com/s/8y5o8x6gi1bu01vd0sk2"}
set end of doubleList to {"002 gerbino-ƒ.zip", "https://app.box.com/s/hgedmob0rg9wf6bsduc1juoo2k16zcgq"}
set end of doubleList to {"003 questions_réponses.pdf.zip", "https://app.box.com/s/2fj57sqkl50zwetqaar7"}
-- to be continued with other pairs

set simpleList to {}
repeat with aPair in doubleList
	set end of simpleList to (item 1 of aPair) as string
end repeat
simpleList

set myChoice to choose from list simpleList
if myChoice is false then error number -128
set indx to (text 1 thru 3 of item 1 of myChoice) as integer
set myLink to item 2 of item indx of doubleList

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 21 avril 2020 22:42:51

I see that you grab the link on safari. As you say, it’s quite complicated… wouldn’t it be easier to do it in finder (when you use Box Sync or Box Drive). There you can easily select the file, then I do an right click (but I don’t know that commando) and then click ‘Copy link’. The advantage is that in finder, the file is more easily to locate.

But, after some searching on the internet, I found the page:

https://developer.box.com/reference/

On this page, one can find a lot of commando’s to work with Box, but they are not in AppleScript. Is there a way to call them from AppleScript, since that would be a more elegant (since you acces Box directly and one is not going trough System Events)

Forgive me, that I’m doing so difficult…

I am reluctant to install items which I don’t have real use so I never installed the Box app and of course didn’t installed its extension Box Drive.
I just did it and the result is:

set theBundle to ((path to application "Box" as string) & "Contents:Resources:Box UI.app") as «class furl»
set copySharedLink_loc to localized string "Copy Shared Link" in bundle theBundle
set share_loc to localized string "Share" in bundle theBundle

set the clipboard to "" -- Clear the clipboard

tell application "System Events" to tell application process "Finder"
	set frontmost to true
	set theSelection to value of attribute "AXFocusedUIElement"
	tell theSelection to perform action "AXShowMenu"
	-- Now the contextual menu is revealed
	tell window 1
		-- class of UI elements --> {splitter group, UI element, button, button, button, toolbar, image, static text}
		tell splitter group 1
			class of UI elements --> {scroll area, splitter, splitter group, list}
			tell splitter group 1
				-- class of UI elements --> {scroll area}
				tell scroll area 1
					-- class of UI elements --> {outline, scroll bar, scroll bar, static text, image, static text, static text, static text, static text, static text, static text}
					tell outline 1
						-- class of UI elements -->{row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, column, column, column, column, column, column, column, group, menu}
						tell menu 1
							-- class of UI elements -->{menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item, menu item}
							-- name of menu items --> {"Ouvrir", "Ouvrir avec", "Toujours ouvrir avec", missing value, "Placer dans la corbeille", missing value, "Afficher sur Box.com", "Déverrouiller le fichier", "Partager", missing value, "Lire les informations", "Afficher l’inspecteur", "Renommer", "Graver sur le disque…", "Dupliquer", "Dupliquer exactement", "Créer un alias", "Coup d’œil sur « Frameworks.zip »", "Diaporama « Frameworks.zip »", "Partager", missing value, "Copier « Frameworks.zip »", "Copier « Frameworks.zip » en tant que nom de chemin", missing value, "Afficher les options de présentation", missing value, "Tags…", missing value, missing value, "Send to Bear", "Search Here in BBEdit", "Open File in BBEdit"}
							-- name of menu item 9 --> "Partager"
							-- name of menu item 20 --> "Partager"
							tell (first menu item whose name is share_loc)
								click it
								-- name of menu items of menu 1 --> {"Copier le lien partagé", "Envoyer un lien partagé par e-mail", "Gérer les collaborateurs"}
								click menu item copySharedLink_loc of menu 1
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell
	end tell
end tell
set theURL to ""
repeat while (theURL = "")
	try
		delay 0.1
		set theURL to (the clipboard as text)
	end try
end repeat
theURL --> "https://app.box.com/s/q7kfpxk582r87hqw67uy4gib455jg5uj"

Select an item in the choose file dialog of Box then run the script.
Of course you may trigger it with a shortcut given with FastScripts or other dedicated tool.
The dedicated contextual menu will be revealed and the wanted item will be clicked.

Don’t change the way it triggers the menu item share_loc.
There are two items with this name, the Box’s one which is at index 9 and the Apple’s one which is at index 20. So we must explicitly trigger the first one.

As always, I left the instructions (disabled) which I used to get the infos required to reach the items to trigger.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 22 avril 2020 14:27:52

With a bit of luck, somebody will be able to post a piece of code based upon the Java or the CLI SDK available.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 22 avril 2020 14:38:42