Hi I know this should be possible but just having trouble putting the various pieces of applescript code together.
I’ll try to explain what I need to do:
After finishing with a bunch of projects we back them up to an external drive. Usually the backup structure looks like this:
Backup Drive 1 (volume name)
- Main Projects
– Project 1
— Project 1 subfolders…
– Project 2
— Project 2 subfolders…
– Project 3
— Project 3 subfolders…
- Capture Scratch
- Color
Although depending on who makes the backup, occasionally we’ll get a structure like this:
Backup Drive 1 (volume name)
- Backup Drive 1
– Main Projects
— Project 1
---- Project 1 subfolders…
— Project 2
---- Project 2 subfolders…
— Project 3
---- Project 3 subfolders…
– Capture Scratch
– Color
that’s an important part of the problem because the paths are not always consistent.
Basically we just need a way to keep track of which projects are on which backup drives. What I would like to do is to be able to drag and drop either the drive itself, or the Main Projects folder on the drive onto a droplet, and have the script append the drive name and the individual project folder names (and not those folders subfolders) within the Main Projects folder to a list.
That way I will get a searchable txt file looking something like this (the formatting is not super important)
Backup Drive 1
Project 1
Project 2
Project 3
Backup Drive 2
Project 4
Project 5
Project 6
etc
If anyone can help me out I would be greatly appreciative!
thanks in advance.
I’ve “almost” got this working now:
--kyle was here
property projects : "Volumes/Tan-Projects/Projects"
property backupListPath : "Tan-Projects:Admin:Documents:backupList.txt"
property charNewline : ASCII character 10
on run
display dialog "Backup List" & return & return & ¬
"Drag the Project Folder from the Backup Drive onto this droplet and it will add the Project folder names to the Backuplist.txt document" buttons {"OK"} default button 1
set theProjects to choose folder with prompt "Or select the Projects folder now:"
open {theProjects}
end run
on open (theProjects)
--display dialog theProjects as string
tell application "Finder"
--activate
set projectNames to name of folders of folder theProjects
end tell
display dialog projectNames as string
repeat
--Read the BackupList.csv file and get the last backup number used and increment by 1 (tried to make into a subroutine but couldn't get backupNumber to return ok)
try
set backupListFile to open for access file (backupListPath) with write permission
repeat with k from 1 to (count projectNames)
write (item k of projectNames) to backupListFile starting at eof
write charNewline to backupListFile starting at eof
end repeat
close access backupListFile
on error errorMsg number errorNum
try
close access backupListFile
end try
display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
end try
exit repeat
end repeat
end open
Now i just need a way to add the name of the Backup drive volume to the list. I think I can do that by getting item 1 of the path to the backup drives Main project folder?
Finder items have a property ‘disk’:
set theFile to choose file
tell application "Finder"
set theDisk to (disk of theFile) as text
end tell
The result is of class ‘disk’, hence the coercion.
Thanks! I had ended up with the following, where theProjects is the variable name I assigned the folder selection to:
try
set text item delimiters to ":"
set driveName to first text item of (theProjects as text)
set text item delimiters to ""
on error
set text item delimiters to ""
end try
But your script is much more elegant - I’ll use it instead.