Advertisement
big_smile

Sort files by Spreadsheet

Mar 10th, 2020
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. -- acsv.applescript
  2.  
  3. -- Prompt for headerless, .csv file and starting folder containing the files to process.-- Reads each row of the CSV into a list, splits that list item into file and folder, and-- moves the file into the appropriate folder. If a file does not exist, it skips that-- row processing, and if the folder does not exist, it will make the folder.-- Tested: macOS 10.14.5-- Reference: https://discussions.apple.com/thread/250480620-- VikingOSX, 2019-07-12, Apple Support Communities, No warranties expressed or implied.
  4.  
  5.  
  6. property delim : {","}
  7. property aDesktop : (path to desktop) as aliasproperty csvType : {"public.comma-separated-values-text", "public.delimited-values-text"}
  8.  
  9. set rowItems to {}
  10. set afile to ""set afolder to ""
  11.  
  12. set csvFile to (choose file with prompt "Select CSV file" of type csvType default location aDesktop without invisibles, multiple selections allowed and showing package contents)
  13.  
  14. set start_folder to (choose folder with prompt "Text File Folder" default location aDesktop without invisibles, multiple selections allowed and showing package contents)
  15.  
  16. set csvList to (read csvFile as text using delimiter linefeed) as listtell application "Finder"
  17. repeat with arow in csvList
  18. repeat 1 times
  19. -- use as many variables as you have columns in the CSV
  20. set {afile, afolder} to my csvParse(arow, delim) as list
  21. log afile
  22. log afolder
  23. try
  24. set check_file to (start_folder & afile) as text as alias
  25. on error
  26. exit repeat
  27. end try
  28. try
  29. set check_folder to (start_folder & afolder) as text as alias
  30. on error
  31. make new folder at start_folder with properties {name:afolder}
  32. set check_folder to (start_folder & afolder) as text as alias
  33. end try
  34. move file check_file to folder check_folder
  35. end repeat
  36. end repeatend tellreturn
  37.  
  38. on csvParse(nrow, adelim)
  39. -- replaces the commas in each row of the CSV with newlines
  40. -- returns columns of data return paragraphs of (do shell script "sed -E 's/,/\\'$'\\n/g' <<<" & nrow's quoted form)
  41. end csvParse
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement