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
Related
I have this simple applescsript:
tell application "Finder"
set xfolder to target of Finder window 1
move files of entire contents of xfolder to xfolder
end tell
which will move every file in subfolders of current folder to the parent folder.
I want it to also remove this subfolders after the files are moved.
Can't get it to work...
If by "remove" you mean put the folders in the trash, then this should work.
Keep in mind that there's no error correction here, so (for example) if there are files with duplicate names in the hierarchy, the resulting error will kill the script.
tell application "Finder"
set xfolder to target of Finder window 1
move files of entire contents of xfolder to xfolder
delete folders of entire contents of xfolder
end tell
I'm trying to write an AppleScript that will simply copy the contents (both folders and files) from a specified source folder to a specified destination folder. At the moment my script runs but only copies one file and I can't work out how to get it to copy all files in the folder.
Here's my script:
set sourceFolder to (POSIX file "/Users/benny/Desktop/Projects/Source/Project1") as alias
set destinationFolder to (POSIX file "/Users/benny/Documents/Masters/Project1") as alias
tell application "System Events"
set availableSourceFiles to every file of sourceFolder whose visible is true
set filesOfTargetFolder to files of destinationFolder whose visible is true
end tell
-- if no more source file is available, quit this script
if (count of availableSourceFiles) = 0 then
quit
end if
set sourceFile to (first item of availableSourceFiles) as alias
-- use the Finder to copy the file
tell application "Finder"
-- duplicate the file to the target folder
duplicate sourceFile to destinationFolder
end tell
I'm assuming I need to include a for each type loop but can't get the syntax correct here. Haven't written AppleScripts in many years so trying to remember how it all works.
If the destination "Project1" folder doesn't have stuff in it already, then duplicating the folder is likely to be quicker:
tell application id "com.apple.Finder" to duplicate folder POSIX file ¬
"/Users/benny/Desktop/Projects/Source/Project1" to the folder ¬
POSIX file "/Users/benny/Documents/Masters" with replacing
However, if that's not an option, then I'd stick with your method and copy the contents of the folder across instead:
set here to POSIX file "/Users/benny/Desktop/Projects/Source/Project1"
set there to POSIX file "/Users/benny/Documents/Masters"
tell application id "com.apple.Finder" to duplicate ¬
every item in the folder here to there
Bear in mind that if there's a file or folder at any of the destinations that intended to be occupied by one of the incoming source items, Finder will throw an error. You would typically incorporate some sort of check ahead of the copy.
I'm trying to copy all files from a folder to another.
This works only if I specify the full path including the name of the drive and the username.
This works:
tell application "Finder"
set a to folder "Macintosh HD:Users:Michael:Desktop:Files:"
set b to folder "Macintosh HD:Users:Michael:Desktop:Copies"
duplicate every file of a to b
end tell
But I want to have this compatible with any HDD naming and username.
So I'm looking for a relative path, equivalent to ~:Desktop.
The relative path equivalent is
set desktopFolder to path to desktop
tell application "Finder"
set a to folder "Files:" of desktopFolder
set b to folder "Copies:" of desktopFolder
duplicate every file of a to b
end tell
But the Finder has a property desktop which points always to the desktop folder of the current user.
tell application "Finder"
set a to folder "Files:" of desktop
set b to folder "Copies:" of desktop
duplicate every file of a to b
end tell
And – even shorter – the desktop folder of the current user is the "root" folder of the Finder
tell application "Finder"
duplicate every file of folder "Files" to folder "Copies"
end tell
Edit:
The equivalent to
~/Library/Containers/com.apple.iWork.Numbers/Data/Library/Application Support/User Templates
is
((path to library folder from user domain as text) & "Containers:com.apple.iWork.Numbers:Data:Library:Application Support:User Templates:")
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
Sorry, complete beginner here with AppleScripting.
I'm trying to do a very simple thing, move files from one folder to another.
tell application "Finder"
set this_folder to "Users:chris.nicol:Movies:SmartConverter:"
set this_list to every file of this_folder
repeat with i in this_list
--if i does not start with "x" then
move i to "users:chris.nicol:music:itunes:itunes media:automatically add to itunes:"
--end if
end repeat
end tell
However I keep getting an error:
I've tried different commands (count, parentContainer, etc.) on the folder, but I get the same type of error. I've tried different formatting for the folder ...
Users/chris.nicol/Movies/SmartConverter/
Macintosh HD:Users:chris.nicol:Movies:SmartConverter
etc.
Any ideas on what I'm doing wrong?
Thanks in advance,
Chris
Simple tip... if you want to find the proper path you should use try this and look in the results field for the proper path. You'll see that the name of the hard drive, Macintosh HD, is required. Note you could use "choose file" as well if you wanted the path to a file.
(choose folder) as text
Next, the path that you will see is a string. Applescript sees it as a string not a path to a file or folder. As such, when you want to use the string as a path then you must put the word "file" or "folder" in front of it as appropriate to make applescript use it properly. Therefore your script should look like this. Note that the move command can handle a list of files so the repeat loop isn't needed.
set this_folder to "Macintosh HD:Users:chris.nicol:Movies:SmartConverter:"
tell application "Finder"
set this_list to every file of folder this_folder
move this_list to folder "Macintosh HD:Users:chris.nicol:music:itunes:itunes media:automatically add to itunes:"
end tell
Try:
set thisFolder to (path to movies folder as text) & "SmartConverter"
set thatFolder to (path to music folder as text) & "itunes:itunes media:automatically add to itunes"
tell application "Finder" to move files of folder thisFolder to thatFolder
You must have some invisible or otherwise uncopyable files in one of the folders. Either add something like without invisibles to the end of your set this_folder line, or get rid of your loop altogether and simply call
move files of entire contents of this_folder to (the Add Automatically folder)