Applescript to copy each file/folder into new created folder - applescript

I have an Applescript to copy files from one directory to another destination automatically. As I am new in Apple Script and I am facing issue while copying file/folder into newly created folder.
As my script is like this
set dt to (current date) as Unicode text
tell application "Finder"
make new folder at alias "Macintosh HD:Users:XYZ:" with properties {name:dt}
//In above code, new folder create automatically with system date and time on specified location like Tuesday, October 1, 2015 at 12/02/48 PM
copy folder "Macintosh HD:Users:XYZ:Desktop:ABC:" to folder "Macintosh HD:Users:XYZ:"
//In above code, I am facing issue that I am not able to copy file into created newly system date and time folder. How can I copy folder into newly created system date and time folder?
end tell
Can any one please help me?
Thanks in advance.

First of all, the Finder command to copy items is duplicate.
make new folder returns a reference to the new folder. Use this reference as destination.
set dt to (current date) as Unicode text
tell application "Finder"
set newFolder to make new folder at alias "Macintosh HD:Users:XYZ:" with properties {name:dt}
duplicate folder "Macintosh HD:Users:XYZ:Desktop:ABC:" to newFolder
end tell

Related

Move every file of every folder to another folder

I am looking to write an AppleScript to move every file in every folder to another folder.
Currently, this is what I have:
tell application "Finder"
move (get every file of every folder of folder "Source_Folder" of desktop) to folder "Destination_Folder" of desktop
end tell
But this throws an error saying: error "Finder got an error: Can’t get document file \"ALGE71FL.cpg\" of folder \"Destination_Folder\" of folder \"Desktop\" of folder \"THIS_USER\" of folder \"Users\" of startup disk." number -1728 from document file "ALGE71FL.cpg" of folder "Destination_Folder" of folder "Desktop" of folder "THIS_USER" of folder "Users" of startup disk
Where ALGE71FL.cpg is the first file of interest.
Any solutions to this?
If you are looking to move only the files in the folders and not the folders themselves. This following AppleScript code is one way to achieve your goal.
activate
set searchFolder to choose folder with prompt "Choose The Folder To Search"
activate
set destinationFolder to choose folder with prompt "Choose The Folder To Move Files To"
tell application "Finder"
set theFiles to (files of entire contents of searchFolder) as alias list
move theFiles to destinationFolder
end tell

Copy contents of Downloads to newly created folder with Applescript

I have the below code, which works to copy the contents of Downloads to the desktop. What I would like to do is copy it to the newly created folder, the folder_name, which is the current date and time.
set folder_name to (current date)
set folder_name to folder_name as string
tell application "Finder"
set p to path to desktop
make new folder at p with properties {name:folder_name}
end tell
tell application "Finder"
move (files of alias "Macintosh HD:Users:XXXXX:Downloads") to desktop
end tell
Essentially, I'm not sure how to pass folder_name into the final path. I tried (desktop & folder_name)
Thanks
The make new folder command of the Finder returns the new folder.
And there is a relative path to the Downloads folder of the current user
set currentDate to (current date) as string
set downloadsFolder to path to downloads folder
tell application "Finder"
set currentFolder to make new folder at desktop with properties {name: currentDate}
move (files of downloadsFolder) to currentFolder
end tell

Can't make folder of application file into integer in applescript

I am trying to write a simple applescript to move the contents of a file into the package contents folder of an application. I tried using automator to do this, but I was unable to access the package contents of the application. I am very new to applescript but this is what I have written so far.
tell application "Finder"
set source_folder to (choose folder with prompt "Select the Step5 Folder:")
set target_folder to folder "MacintoshHD:Applications:BlueJ.app:Contents:Resources:Java:userlib"
copy every file in folder source_folder to folder target_folder
end tell
Right now I am getting the following error
error "Finder got an error: Can’t make folder \"userlib\" of folder \"Java\" of folder \"Resources\" of folder \"Contents\" of application file \"BlueJ.app\" of folder \"Applications\" of startup disk into type integer." number -1700 from folder "userlib" of folder "Java" of folder "Resources" of folder "Contents" of application file "BlueJ.app" of folder "Applications" of startup disk to integer
I have tried googling the error and I have not found anything that has been applicable to what I am writing.
Thanks
Try:
set source_folder to (choose folder with prompt "Select the Step5 Folder:")
set target_folder to "MacintoshHD:Applications:BlueJ.app:Contents:Resources:Java:userlib"
tell application "Finder" to duplicate files of source_folder to target_folder
You specified 'folder' twice... the error was for moving the file to: folder folder path

How to create a folder (with subfolders) with Applescript

Filemaker has the ability to ake use of AppleScript.
From within Filemaker I want to create a new folder (with the name of a FileMaker field) that holds 6 subfolders.
I am a complete noob where it comes to Applescript.
This is my script so far:
tell application "FileMaker Pro Advanced"
set folder_name to cell "FolderName" of current record
end tell
tell application "Finder"
activate
make new folder at folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:folder_name}
end tell
tell application "Finder"
activate
make new folder at folder {name:folder_name} of folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:"subfolder"}
end tell
My problem is: the creation of "Subfolder1"
What is my mistake there?
Help is much appreciated
When you crate a new folder you can define various properties, but when refering to the folder just use the name, for example:
make new folder at folder folder_name of folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:"subfolder"}
Note that the result returned from making a new folder is a reference to that folder, so you can also do something like:
tell application "Finder"
set newFolder to (make new folder at folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:folder_name})
make new folder at newFolder with properties {name:"subfolder"}
end tell
Here is another approach:
set myPath to POSIX path of ((path to desktop as text) & folder_name & ":subfolder")
do shell script "mkdir -p " & myPath

How to get the latest downloaded file name with applescript programatically?

I need to get the file name programatically on Mac, am using Selenium to download the file and from downloads folder i need to pick the same file to install programatically, am using Applescript to do the same. I am stuck in getting the file name in runtime, also my download page url doesnot contain full name of the download file. Pls suggest..
This will give you the latest file (sorted by creation date) of your downloads folder:
tell application "Finder"
set latestFile to item 1 of (sort (get files of (path to downloads folder)) by creation date) as alias
set fileName to latestFile's name
end tell
Yes Mavericks does open the oldest, but this seams to work by specifying the last item.
tell application "Finder"
set latestFile to last item of (sort (get files of (path to downloads folder)) by creation date) as alias
set fileName to latestFile's name
end tell

Resources