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:
Select a file somewhere in Dropbox, in a nested folder.
Copy the public link (so someone with web access can download the file)
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)
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.
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.
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.
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
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