Dropbox file paths

This is an amazing resource. Especially for a non-scripter like myself. Thank you all! Meanwhile, I’m trying to figure out how to automate this process:

  1. Select a file somewhere in Dropbox, in a nested folder.
  2. Copy the public link (so someone with web access can download the file)
  3. ALSO copy the actual path on my hard drive (so people who are synced with my Dropbox folders can find the file on their own hard drive)
  4. Replace the “Macintosh HD/User/Dropbox…” part of the path with “~/Dropbox…” so they can just paste the text into their Go to Folder menu in Finder.
  5. Put all that into the Clipboard so I can paste it into an email or a text field in a browser window, etc. – wherever I happen to need it.

I know how to do these things manually, of course, but it’s a pain to do it a lot. And I do.

Ideally, the end result would look like this:

Link to file: https://www.dropbox.com/s/ukzqhd1ejcpzhte/Test%20note%20from%20NVAlt.txt?dl=0
Path on your hard drive: ~/Dropbox/Apps/NVAlt/Test note from NVAlt.txt

If it helps, I have Hazel, LaunchBar and of course Automator and Script Editor to play with. Thanks for any help you can give me!

(Note: Operating systems comes up as 10.8, but I’m actually on Yosemite 10.10)

Model: MacBook Pro
AppleScript: 2.4
Browser: Safari 600.1.25
Operating System: Mac OS X (10.8)

Hi Josh,

This does most of what you want except the creating message in Mail. That is really easy though.

-- get a reference to the dropbox folder for choose file's default location
set dropbox_folder to ((path to home folder as string) & "Dropbox:") as alias
-- user selects the file
set file_ref to choose file with prompt "Choose the Dropbox file:" default location dropbox_folder
-- get local file url
tell application "System Events"
	set file_url to URL of file_ref
end tell
-- get posix path of file
set file_pp to POSIX path of file_ref
-- replace user home folder with "~"
set tids to AppleScript's text item delimiters
set AppleScript's text item delimiters to "/"
set temp_list to text items of file_pp
set local_file_pp to "~/" & ((items 4 thru -1 of temp_list) as string)
set AppleScript's text item delimiters to tids
-- place the local posix path on the clipboard
set the clipboard to local_file_pp
-- look at result
return {file_url, the clipboard}

Not sure what you want to do with the local file url.

gl,
kel

I have an AppleScript that finds and orange tags files within any specified directory, however it is unable to find files within a dropbox folder. Not sure why this does not work. Below it the script. Ideas on how to modify this is appreciated.
Thanks
DKPictureman



set the_folder to the POSIX path of (choose folder with prompt "Please select a folder to process:")
display dialog "Which files do you want to be labled?
(one file per line)" default answer linefeed
set name_list to text returned of the result

set AppleScript's text item delimiters to ASCII character 10
if the number of text items of name_list < 2 then set AppleScript's text item delimiters to ASCII character 13 

set name_list to every text item of name_list
log name_list
log the_folder
set file_counter to 0
set found_files to 0
repeat with n in name_list
	if length of n > 0 then
		set file_counter to (file_counter + 1)
		set file_paths to every paragraph of (do shell script "mdfind -onlyin " & the_folder & " -name " & n & "")
		repeat with n in file_paths
			set the_file_path to POSIX file n
			set the_file_path to the_file_path as alias
			tell application "Finder"
				set label index of the_file_path to 1
				set found_files to (found_files + 1)
			end tell
		end repeat
	end if
end repeat
set confermation to ((file_counter as string) & " total files searched for and  " & found_files as string) & " Found "
tell application "Finder"
	do shell script "say  PhotoMatch selection finished" & confermation
end tell
activate
display dialog confermation & the_folder
tell application "Finder"
	if front Finder window exists then
		set target of front Finder window to the_folder as POSIX file
	else
		open the_folder as POSIX file
	end if
	activate
end tell

As far as I know it’s safe to quote the passed POSIX path in case it contain one or several characters needing to be escaped (space char for instance)
I made some other changes.

set the_folder to the POSIX path of (choose folder with prompt "Please select a folder to process:")
display dialog "Which files do you want to be labled?
(one file per line)" default answer linefeed
set name_list to text returned of the result

set AppleScript's text item delimiters to {linefeed} -- EDITED
if the number of text items of name_list < 2 then set AppleScript's text item delimiters to {return} -- EDITED

set name_list to every text item of name_list
log name_list
log the_folder
set file_counter to 0
set found_files to 0
repeat with n in name_list
	if length of n > 0 then
		set file_counter to (file_counter + 1)
		set file_paths to every paragraph of (do shell script "mdfind -onlyin " & quoted form of the_folder & " -name " & n & "") -- EDITED
		
		repeat with n in file_paths
			set the_file_path to POSIX file n
			set the_file_path to the_file_path as alias
			tell application "Finder"
				set label index of the_file_path to 1
				set found_files to (found_files + 1)
			end tell
		end repeat
	end if
end repeat
set confermation to ((file_counter as string) & " total files searched for and  " & found_files as string) & " Found "
(*
tell application "Finder"
	do shell script "say  PhotoMatch selection finished" & confermation -- DISABLED
end tell
*)
tell me to say "PhotoMatch selection finished" & confermation -- ADDED
activate
display dialog confermation & the_folder
tell application "Finder"
	if front Finder window exists then
		set target of front Finder window to the_folder as POSIX file
	else
		open the_folder as POSIX file
	end if
	activate
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 18 mai 2020 19:53:07

Thank YOU very much that works!!! How would one when opening the last finder window to the folder searched open it up in grouped by taged?

Would help to apply the shortcut cmd + J.
You will be proposed to group files of a window by tags.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 18 mai 2020 20:46:08

Sorry, excuse my ignorance.
how is this scripted?

Would help to apply the shortcut cmd + J.
You will be proposed to group files of a window by tags.


tell application "Finder"
   if front Finder window exists then
       set target of front Finder window to the_folder as POSIX file
   else
       open the_folder as POSIX file
   end if
   activate
end tell


I apologizes but I didn’t understood that you wanted to do that in a script.

Look at the long thread : https://macscripter.net/viewtopic.php?id=47311 whose at least two pages are dedicated to such task.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 18 mai 2020 21:53:02

put after the snippet above this snippet:


tell application "System Events" to keystroke "7" using {control down, command down}