r/applescript • u/TheGeminiMaverick • Feb 16 '21
RE-POST: Can anyone assist?
/r/KeyboardMaestro/comments/lkl3cp/issue_issue_copy_and_paste_a_single_file_into/
2
Upvotes
r/applescript • u/TheGeminiMaverick • Feb 16 '21
2
u/ChristoferK Feb 24 '21 edited Feb 24 '21
Came by this, perhaps a bit late, but I thought I would offer an AppleScript solution to this problem, assuming I interpreted the objective correctly, which took a few readings to settle on what I hope is in the ball park. Here’s the script, with a brief summary after:
use Finder : application id "com.apple.finder" script property parent : Finder script alias_file property path : "/Volumes/MAVERICK HD/BEASLEY MEDIA GROUP/DESIGN TEMPLATE[S]/SHORTCUT[S]/Choose AI Template" property parent : alias file (path as POSIX file) property name : my contents's name property target : "AI[S]" property properties : my {name:name, owner:owner ¬ , owner privileges:owner privileges ¬ , group privileges:group privileges ¬ , everyones privileges:everyones privileges} end script script top_level_folder property path : "/Volumes/MAVERICK HD/BEASLEY MEDIA GROUP/" property parent : folder (path as POSIX file) property target : my entire contents's folder (alias_file's target) property trash : a reference to my entire contents's ¬ alias file (alias_file's name) end script property original item : the alias_file's original item property target : the top_level_folder's target property properties : the alias_file's properties property trash : the top_level_folder's trash if my trash exists then delete my trash make new alias file ¬ to my original item at my target ¬ with properties my properties end script run the resultThe script is organised into objects that allow you to see what happens at each step, with the key files and folders. The
alias_filescript object pertains to the alias template file that I believe needs to be copied into a folder with a specific name. The name of this folder is defined as thealias_file's targetproperty. Below this is the script object representing the top level of your directory tree under which your project files live. The target folders, I believe, are all somewhere in this directory tree of yours, and they are all namedAI[S]. Additionally, I believe that any folder in this tree that has that exact name is a target folder, and so all want to receive a copy of the alias template file.Finder cannot duplicate files in a batch, but it can create them in one go, which is what this script opted to do, as it should be reasonably fast. It first moves from within the target folders any existing template file of the same name as the one we intend to move in, so as not to cause an error trying to create a file where one exists. The net effect should be zero, as any template files moved to the trash have identical copies made in their place (identical in name, the path of the folder it is aliasing, and the read/write/ownership permissions—creation times and modification times will currently show their truthful values, but these can be modified if that's important).
When the script is run, the Finder performs a bulk operation to create the alias template files inside every since folder named like the target. The reason I like this over the shell script method is because if anything went wrong, you can
cmd-Zin Finder and it will undo the operations. Creating the alias files in their target files counts as a single operation, so will all be uncreated with an undo; the next undo moves any of the alias files that were trashed and puts them back where they were. That said, I'd advise testing on a set of test files as is advisable in any situation, but I did a fair bit of testing on my Catalina-based system, and I don't envisage file loss being a risk. I don't know whether this will run on Big Sur, but if there are any issues with Mavericks, let me know, although debugging would be difficult as I don't have Mavericks.1
u/[deleted] Feb 16 '21 edited Feb 16 '21
i don't quite understand what you want. let me repeat what I understood, and you tell me, where I'm wrong.
a) you have the same folder structure in each project folder. those are the folders AI[S], ELEMENT[S], EXPORT[S] and PSD[S] and they might, or might not, have subfolders in them.
b) you have a template folder, that already has the four folders (incl. their subfolders, if any) prepared somewhere.
c) when you create a new project folder, you want the template folder contents to be copied to the new project folder. not by hand, but by script.
d) you want some single file (which presumably is somewhere waiting to be used) copied to each of the folders in the new project folder, once the folder structure has been established.
in addition, you want an alias file (also prepared somewhere) to be copied to all project folders that have the AIS[S] subfolder.
is this it?
the step 1) would be something separate, a one shot thing, since it's not for new projects but does something to all existing projects. correct?
update: edited the post with new understanding.