Can't make folder of application file into integer in applescript - 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

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

AppleScript - Copy All files/folders from source folder to destination folder

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.

What is the applescript code to open a folder

Right now I am using this code:
open folder
and it seems like it can not find the folder.
Do I have to specify a folder?
Basically open does not open folders.
You have to open a folder via the Finder and specify an HFS string path, alias or Finder folder specifier:
tell application "Finder" to open (path to desktop)
or
tell application "Finder" to open home
or
tell application "Finder" to open folder "Applications" of startup disk

Applescript error when trying to get file list from folder

I'm having trouble getting AppleScript to read a list of files from a folder without receiving the error message "Can't get every file from folder XXX"
set targetfolder to ("DICTAPHONE:DSS_FLDA:")
tell application "Finder"
set fileselection to every file in targetfolder
endtell
This worked flawlessly before upgrading to Mavericks. Paths are correct. I tried it with a different folder on my startup disk and got the same result.
Try using folder targetfolder instead of targetfolder:
set targetfolder to ("Macintosh HD:Library:Desktop Pictures")
tell application "Finder"
files of (folder targetfolder)
end tell
Try this to get the information:
set targetfolder to (path to desktop as alias)
tell application "Finder"
set fileselection to get the name of every file of targetfolder
end tell

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

Resources