Mac Automator: Mass-create Subfolders - macos

I am trying to use Automator to take a bunch of previously-created folders and create two new folders within each one, an "Originals" folder and a "Scans" folder. I would like to be able to drag or select the folders that need the subfolders and then have the action run automatically.
I've tried making both an action and a service to add the subfolders, but when I select multiple folders, it only runs once.
Here is a screenshot of what I've done so far...

Try saving the workflow as an Application:
Save the Application to your Desktop, then you can drop folders there whenever you want.
Here is an AppleScript that, when Exported as an Application, functions as a Droplet to make the desired folders in every folder dropped thereon:
on open droppings
repeat with everyDrop in droppings
if (info for everyDrop)'s folder is true then
--make two folders
tell application "Finder"
make new folder at (everyDrop as text) with properties {name:"Originals"}
make new folder at (everyDrop as text) with properties {name:"Scans"}
end tell
end if
end repeat
end open
on run
display dialog "Drop some folders here to add Originals and Scans folders" buttons {"Aye Aye"} default button "Aye Aye"
end run

Related

How to duplicate desktop file on applescript

I'm trying to duplicate my desktop file on apple script using script editor but I can't figure out how to do it. Can someone please help me?
The following command will duplicate your Desktop folder in Finder as Desktop copy and will be in your Home folder:
tell application "Finder" to duplicate desktop
The following commands will duplicate the target object directly on the Desktop, i.e., objects within the Desktop folder in your Home folder in Finder .
The following command will duplicate every file on your Desktop:
tell application "Finder" to duplicate every file of desktop
The following command will duplicate every folder on your Desktop:
tell application "Finder" to duplicate every folder of (path to desktop)
The following command will duplicate every file and folder on your Desktop:
tell application "Finder" to duplicate every item of (path to desktop)
NOTES:
This is to address the comment made by has:
As to: "1. You don’t need path to desktop as Finder’s application object already has a desktop property containing a reference to the user’s Desktop."
This is not categorically a true statement and depends on how it's being used. It's true with the Desktop folder itself and files within the Desktop folder, however it is absolutely false with duplicate every folder of and duplicate every item of, and without using (path to desktop) in these instances it errors out with the following error statement:
"Finder got an error: The folder “” can’t be moved into itself." number -122
As to: "2. Never do duplicate every item of desktop – if the Finder’s preferences are set to display mounted volumes on the Desktop then those will be included too, and you definitely don’t want to duplicate those!"
That statement is categorically false!
He/she (has) obviously doesn't know what he/she is talking about because mounted volumes are not located within the Desktop folder in your Home folder. By default, they are mounted at /Volumes and while they can appear on the Desktop, they are not directly connected to the Desktop folder in your Home folder.
In this reference the Desktop and Desktop folder in your Home folder are not the same thing!

moving one folder to another folder - applescript

I'm trying to move a user-selected folder to another folder, but I don't get it: whenever I look it up, it looks too complicated, even though I know it's not supposed to be.
Here's the code I have so far - please help:
choose folder with prompt "Select folder:"
on open of finderObject
tell application "Finder" to move (finderObject) to folder "Library:Application Support"
end open
end
First off, you have to assign the chosen folder to a variable.
Also, many special folders in the OSX file structure have special names to get their paths, including the library and the application support folders. So, your script can simply be:
set finderObject to choose folder with prompt "Select folder:"
tell app "Finder" to move finderObject to folder (path to Application Support folder from local domain as string)
However, that is the root level Library folder. I suspect you will want to use the Application Support folder in the ~/ user domain. For that, change the "from local domain" to "from user domain".

How to copy/paste one or more files in AppleScript?

i've created an AppleScript that allows me to create a folder in my computer in a desired location:
Here is the script:
set folderName to text returned of (display dialog "Please enter Folder Name:" default answer "Folder_Name")
set loc to choose folder "Choose Parent Folder Location"
tell application "Finder"
set newfolder to make new folder at loc with properties {name:folderName}
end tell
What I want now, is it possible to copy and paste files (template) in this folder that i just created with my AppleScript?
The files (template) would be placed in the same folder as the AppleScript.
And also, is it possible to create an app with my script and put the files (template) in content folder of app for works properly?
PS: I'm a newbies in AppleScript, my code in the current state it is good?
All this is possible. But I'm not sure I have understand all quite correct.
To create and AppleScript Application in AppleScript Editor and show the Resources Folder:
Choose Save.
In the save Dialog choose your save destination.
Choose File Format: Application.
Click Save.
Navigate to the App in Finder, right click it and select "Show Package Content".
The opened folder will contain a folder named Contents in this there is the Resources folder. Put the files there or create them there.
To get the path to this folder use:
set resPath to (path to me as text) & "Contents:Resources:"
(The above script won't work as excepted in AppleScript Editor. You have to run the script as an app)(Seems that you can now test this out of Script Editor)
You can now copy your template files like this:
set resPath to (path to me as text) & "Contents:Resources:"
tell application "Finder" to duplicate resPath & "aTemplate.txt" to loc
BTW: You can access the Resources folder directly via the Scrip Editor if you click Bundle Contents in the toolbar.

How to run script upon opening folder?

I want to run an applescript when a specific folder of mine is opened. Then, depending on the input, close the folder, or leave it open. All that without opening the folder. So, basically:
1) Try to open folder
2) Folder doesn't open, but window pops up
3-A) If user clicks ok folder opens
3-B) If user clicks cancel, it just exits out of script, leaving the folder unopened.
How can I do this? Remember: The folder CAN'T open in the background, it can ONLY open if the user presses OK. Help?
For this task, you'll want to use Folder Actions, which trigger script files. Below are the events involving a folder that could trigger a script, and the special corresponding handlers.
A folder is opened — on opening folder window for this_folder
A folder is closed — on closing folder window for this_folder
One or more items are added to a folder on adding folder items to this_folder after receiving these_items
One or more items are removed from a folder — on removing folder items from this_folder after losing these_itmes
A folder window is moved — on moving folder window for this_folder
The first bullet is what you'll be focusing on in this case. As the bullet implies, the script is triggered only when the folder actually opens. However, you can hack your way around this issue simply by adding this line at the very beginning of your script:
tell application "Finder" to close first window whose target is this_folder
And here is the full script:
on opening folder window for this_folder
tell application "Finder"
close first window whose target is this_folder
-- the window may appear briefly, but at least you've accomplished your goal
display dialog "Open folder " quoted form of the name of this_folder & "?" buttons{"Yes,"No"} default button 1 cancel button 2
-- pressing the "No" button is exactly the same as pressing the "Cancel" button on a regular dialog, and the script terminates
make new Finder window with properties {target:this_folder}
end tell
end opening folder window
SAVE YOUR SCRIPT FILE IN THE FOLDER ACTIONS FOLDER OF YOUR LOCAL SCRIPTS FOLDER. Create the folder yourself if it doesn't already exist. Doing so will allow your script to even run. Now, for this to function properly, you will need to attach the saved script file—not an application/application bundle—to your desired folder. To do this...
Perform a right-click on your desired folder
Click the menu item "Folder Actions Setup" at the bottom
Locate your saved script in the dialog that appears
Click "Attach"
Close the "Folder Actions Setup" window
Once you've done this, your script is ready to go.
Addendum: If your folder contains confidential information, beware that, as stated by user57368, "it is probably not possible to make the system even remotely secure with AppleScript."
Instead of an ordinary folder, you want an application bundle containing a folder or disk image. If you use an encrypted disk image, it will be more difficult for the user to access the contents without following your preferred procedure, but beware that it is probably not possible to make the system even remotely secure when you're using AppleScript.
If you just want to present a license agreement or other static notice before allowing the user to read the data, just read the hdiutil man page for how to create a disk image that presents a license agreement upon mounting.

Renaming Files Sequentially as they are added to a folder using Automator or Applescript

I need to rename image files sequentially as they are added to a folder. ie. image-0001.jpg and image-0002.jpg are in a folder I add test.jpg and it is renamed image-0003.jpg. I have tried automators rename function but it will start over with image-0001.jpg each time a new file is added instead of continuing the sequence.
Any help is greatly appreciated.
You could make this easy on yourself by using a handy application built into the OS called "Folder Actions". Folder Actions contains one or more special handlers, formally known as folder action event handlers, that run when they are triggered by a change in the target folder. I know I'm confusing but I'll do my best.
What you are trying to accomplish requires an adding folder items to event handler. It requires one direct parameter, which can be anything you wish i.e. target_folder. The handler requires an additional parameter as well; after receiving, which should also be a variable name, i.e. these_items. I have composed a script for you that should do the trick. I have added comments that show you what I'm doing when I do it. Here it is:
on adding folder items to the target_folder after receiving these_items
tell application "Finder"
set all_images to every item of the target_folder as list
repeat with i from 1 to the count of these_items --iterates through all the items you dropped in the folder
set this_image to item i of these_items --the current image
set the name of this_image to "image" & (i + the count of all_images) as string --renames the image based on the number of images already in the folder
end repeat
end tell
end adding folder items to
YAY! The script is done! But are WE done? Not quite. We still need to attach the script to a folder (the script won't run if you try to execute it in script editor).
To do this, first save the script as a Script File in the Folder Action Scripts folder in the Scripts folder in either the local Library folder or the current user's Library folder. Create the folder yourself if it doesn't already exist. Next, launch the Folder Actions Setup application by double-clicking it in the AppleScript folder in the Applications folder. In the window that comes up, click the + button under the table on the left (click the "Enable Folder Actions" checkbox if it isn't already checked) to open a standard file browser sheet, navigate to your desired folder, and click "Open". The Choose a Script to Attach sheet automatically opens, listing all the scripts in all of the Folder Action Script folders. Choose the newly-created script, click "Attach", and BAM you are done!
To see the script in action, drag an image onto the folder. The image is instantly renamed, regardless of if the folder window is open. If you have any questions, or if the script doesn't work, just ask me. :)
well without digging through some code and handin you an answer I'll tell you want you want to do
is create a while loop that checks for the existence of image-000 & i where i is a variable of course and if it exists increment i then when the file doesn't exist rename your file.

Resources