I'm trying to create a folder structure using applescript. This code works great locally, but when I try it on a networked drive it returns "Can't get <> "test" of application "Finder".
This is the code I have
tell application "Finder"
set campaignName to text returned of (display dialog "Please enter Campaign Name:" default answer "Campaign Name")
tell application "Finder" to set currentDirectory to target of Finder window 1
make new folder at currentDirectory with properties {name:campaignName}
make new folder at folder campaignName with properties {name:"a-creative"}
make new folder at folder "a-creative" of folder campaignName with properties {name:"a-assets-from-client"}
make new folder at folder "a-creative" of folder campaignName with properties {name:"b-art-director-files"}
make new folder at folder "a-creative" of folder campaignName with properties {name:"c-for-production"}
make new folder at folder "a-creative" of folder campaignName with properties {name:"d-developer-notes"}
make new folder at folder "b-art-director-files" of folder "a-creative" of folder campaignName with properties {name:"PSD"}
make new folder at folder "b-art-director-files" of folder "a-creative" of folder campaignName with properties {name:"storyboard"}
end tell
I'm hoping someone can help me figure out what I'm doing wrong here. I'm new to using applescript.
Thank you!
Try it this way:
tell application "Finder"
set campaignName to text returned of (display dialog "Please enter Campaign Name:" default answer "Campaign Name")
tell application "Finder" to set currentDirectory to target of Finder window 1
set projectFolderRoot to make new folder at currentDirectory with properties {name:campaignName}
set aCreativeRoot to make new folder at projectFolderRoot with properties {name:"a-creative"}
set bArtDirectorRoot to make new folder at aCreativeRoot with properties {name:"b-art-director-files"}
make new folder at aCreativeRoot with properties {name:"c-for-production"}
make new folder at aCreativeRoot with properties {name:"d-developer-notes"}
make new folder at bArtDirectorRoot with properties {name:"PSD"}
make new folder at bArtDirectorRoot with properties {name:"storyboard"}
end tell
Related
Using Automator, I created a "Folder Action" to move files of certain types (i.e. "Kind IS Movie") from folder "FolderA" to folder "FolderB" as soon as they are added to folder "FolderA". It works fine except that it doesn't move files from subfolders (e.g. doesn't work if the movie files are added to "FolderA/SubA/"), and apparently there's no option on Automator to make it work on the subfolders.
Does anyone have any idea about how to either change that on Automator or how could I create a script for that? Thanks!
This following AppleScript folder action code should give you a general idea of how to accomplish what you are looking for. When a file or folder is added to a folder that this folder action is attached to, it will search all folders and sub folders for files (I used QuickTime movie as the kind of file... But you can change that to whatever you want) then those files will be moved to the folder that you will define in property moveToFolder
You can save this following code in Script Editor.app directly into your /Users/Your_User_Name/Library/Workflows/Applications/Folder Actions folder, as a .scpt file. Once the script is saved into that folder, it will be available to attach to any folder as a folder action using the Folder Actions Setup.
-- Set This To The Folder You Want Your Videos Moved To
property moveToFolder : (path to desktop as text) & "moved_videos"
-- Set This To The Kind Of File To Act Upon
property fileKind : "QuickTime movie"
on adding folder items to theFolder after receiving theNewItems
tell application "Finder"
set movieFilesRef to a reference to (files of entire contents of folder theFolder ¬
whose kind is fileKind)
move movieFilesRef to alias moveToFolder
end tell
end adding folder items to
OR Here Is A Version Which Defines The Name Extensions Of The Files To Act Upon
-- Set This To The Folder You Want Your Videos Moved To
property moveToFolder : (path to desktop as text) & "moved_videos"
-- Set This To The Name Extensions Of Files To Act Upon
property videoFileExtensions : {"m4v", "mkv", "avi", "mp4", "mov", "wmv", "mpg"}
on adding folder items to theFolder after receiving theNewItems
tell application "Finder"
set movieFilesRef to a reference to (files of entire contents of folder theFolder ¬
whose name extension is in videoFileExtensions)
move movieFilesRef to alias moveToFolder
end tell
end adding folder items to
(noob / novice) here I have done many searches online but cannot get this to work
I am trying to get a file duplicated from a pre-determined location into a newly created folder from within the script.
The script basically asks for a few bits of info and creates a folder structure using the info and a predefined set of folder within. from there I would want it to copy some template files (.psd .fcpbundle etc) from a template folder on the HDD.
my code is as follows now it all works up until it tries to copy the file
tell application "Finder"
set JobName to text returned of (display dialog "Please enter the wedding date" default answer "YYYY/MM/DD") --Asks for date of wedding
set DT to text returned of (display dialog "Please enter the couples name" default answer "Bride & Groom + Surname") --Asks for couples name
set Wedding to text returned of (display dialog "Please enter the type of day" default answer "Wedding") --Asks for type of day, Wedding, Party, etc
--Creates directory with info from above
set loc to choose folder "Please choose where you would like to save the files" --Loc = Location of where directory will be placed
set newfoldername to JobName & " - " & DT & " - " & Wedding --Adds Date, Couples name and event type to make directory name
--Creates parent directory
set newfo to make new folder at loc with properties {name:newfoldername} --Directory name defined
set audio to make new folder at newfo with properties {name:"Audio"} --creates Audio Directory
set doc to make new folder at newfo with properties {name:"Documents"} --creates Documents Directory
set exports to make new folder at newfo with properties {name:"Exports"} --creates Exports Directory
set fpcx to make new folder at newfo with properties {name:"FCPX Library"} --creates FCPX Directory
set filmposter to make new folder at newfo with properties {name:"Film Poster"} --creates FilmPoster Directory
set finaldel to make new folder at newfo with properties {name:"Final Delivery"} --creates Final Delivery Directory
set images to make new folder at newfo with properties {name:"Images"} --creates Images Directory
set rawcards to make new folder at newfo with properties {name:"RAW Cards"} --creates RAW Cards Directory
set xml to make new folder at newfo with properties {name:"XML"} --creates XML Directory
--Creates sub-folders
set submusic to make new folder at audio with properties {name:"Music"} --creates Music in Audio Directory
set subrawaudio to make new folder at audio with properties {name:"RAW Audio Cards"} --creates RAW Audio Cards in Audio Directory
set subdvd to make new folder at finaldel with properties {name:"DVD"} --creates DVD in Final Delivery Directory
set subusb to make new folder at finaldel with properties {name:"USB"} --creates USB in Final Delivery Directory
set subweb to make new folder at finaldel with properties {name:"WEB"} --creates WEB in Final Delivery Directory
set subgraphics to make new folder at images with properties {name:"Graphics"} --creates Graphics in Images Directory
set substills to make new folder at images with properties {name:"Stills"} --creates Stills in Graphics Directory
set subcam_1 to make new folder at rawcards with properties {name:"Cam-1"} --creates Cam-1 in RAW Cards Directory
set subcam_2 to make new folder at rawcards with properties {name:"Cam-2"} --creates Cam-2 in RAW Cards Directory
set subcam_3 to make new folder at rawcards with properties {name:"Cam-3"} --creates Cam-3 in RAW Cards Directory
--Moves files from template directory to working directory
set sourceFile to POSIX file "/Users/ricoh-admin/Movies/WeddingTemplate Creator/2005_0001.rtf"
set destFolder to POSIX file "loc & finaldel & subdvd"
tell application "Finder"
duplicate POSIX file sourceFile to destFolder
end tell
end tell
Any help would be appreciated and to know where I went wrong etc
You are mixing up POSIX paths and HFS paths.
This version creates the entire folder structure in one line via the shell (this requires a slash separated POSIX path)
The Finder duplicates the RTF file which requires colon separated HFS paths.
tell application "Finder" to set frontmost to true
set JobName to text returned of (display dialog "Please enter the wedding date" default answer "YYYY/MM/DD") --Asks for date of wedding
set DT to text returned of (display dialog "Please enter the couples name" default answer "Bride & Groom + Surname") --Asks for couples name
set Wedding to text returned of (display dialog "Please enter the type of day" default answer "Wedding") --Asks for type of day, Wedding, Party, etc
--Creates directory with info from above
set loc to (choose folder "Please choose where you would like to save the files") as text --Loc = Location of where directory will be placed
set newfoldername to JobName & " - " & DT & " - " & Wedding --Adds Date, Couples name and event type to make directory name
set folderStructure to "/{Audio/{Music,RAW\\ Audio\\ Cards},Documents,Exports,FCPX\\ Library,Film\\ Poster,Final\\ Delivery/{DVD,USB,WEB},Images/{Graphics,Stills},RAW\\ Cards/{Cam-1,Cam-2,Cam-3},XML}"
do shell script "mkdir -p " & quoted form of POSIX path of (loc & newfoldername) & folderStructure
set sourceFile to (path to movies folder as text) & "WeddingTemplate Creator:2005_0001.rtf"
set destFolder to loc & newfoldername & ":Final Delivery:DVD:"
tell application "Finder"
duplicate file sourceFile to folder destFolder
end tell
I'm in a bit of a bind and an Applescript noob. I've been stumbling through a script that would allow me to copy the contents of (TemplateFolder) into all of the client folders in a directory, with the added crux that all of the existing clients' folder contents be moved into a folder within the client labeled "Old Files" or something of the sort. I'll include images with my script thus far to illustrate what I'm trying to achieve. Thank you everyone in advance for all your help.
P.S. Since I don't have the rep required, I'll have to post links to my images.
http://imgur.com/a/lL9q7
The first image is the template folder (the folder I'd like all contents copied into each client folder).
The second image is an example of an existing client folder with all the bad structure (or lack thereof).
The final image is the expected results where the template folder's contents are moved into the client folder and the original content of the client's folder are moved into a separate folder titled "Old Structure Files".
Below is the applescript I've written, with help from others, to copy the contents. However there are missing components and some elements that need to change; currently the applescript simply copies the entire folder rather than just the contents and it makes a simple copy rather than inserting, the script is not recursive for an entire directory, and there's no function to move the existing client files into a "Old Structure Files" folder. Again, any and all help is greatly appreciated :)
on run
set source_folder to choose folder with prompt "Select folder to be duplicated:" as string
my do_main_script(source_folder)
end run
on open of source_folder_list
repeat with i from 1 to number of items in the source_folder_list
set this_folder_path to item i of the source_folder_list as string
if last character of this_folder_path is ":" then
my do_main_script(this_folder_path)
end if
end repeat
end open
on do_main_script(source_folder)
tell application "Finder" to set source_folder to folder (source_folder)
tell application "Finder" to set the target_folder to (parent of source_folder)
if source_folder is not "" and target_folder is not "" then
set new_folder_name to (name of source_folder as string) & " duplicate"
set source_folder to source_folder as string
set target_folder to target_folder as string
my create_new_folder(target_folder, new_folder_name)
my duplicate_folder_structure(source_folder, target_folder & new_folder_name & ":")
end if
end do_main_script
In the script bellow, the template folder is at fixed place on desktop, all the content of the customer selected folder is moved to a new folder "old structure", and after that, all content of the template folder is duplicated into the customer folder. If I well understand, this is what you're looking for :
set Templatefolder to "HD:Users:my_user:Desktop:Template"
set CustomerFolder to (choose folder with prompt "Select customer folder to be re-organised")
tell application "Finder"
set CustomerData to every item of CustomerFolder
set OldF to make new folder in CustomerFolder with properties {name:"Old Strutucture Files"}
move CustomerData to OldF
set Newstructure to every item of folder Templatefolder
duplicate Newstructure to CustomerFolder
end tell
i am new to this and am looking for help: i have a piece of code that is working but wanna extend it and can't make it work so far:
i have this to create a project folder in a chosen location, with two folders and two subfolders:
`set JobName to text returned of (display dialog "Please enter Project Name:" default answer "New_Project")
set loc to choose folder "Choose Parent Folder Location"
tell application "Finder"
set newfo to make new folder at loc with properties {name:JobName}
set targetFolder to make new folder at newfo with properties {name:"01_folder"}
make new folder at targetFolder with properties {name:"01_sub1"}
set targetFolder to make new folder at newfo with properties {name:"02_folder"}
make new folder at targetFolder with properties {name:"02_sub1"}
end tell`
i have two questions:
1. how can I create a subfolder in subfolder {name:"01_sub1"}?
2. how can I move a file into one of the folder that are being created?
(I know how to move to a fixed path but not one that is being chosen in the process of the same script)
i would be super thankful for any hints!
spoke
You are already doing it in your other lines so I don't understand why you have problems. You have this line:
make new folder at targetFolder with properties {name:"01_sub1"}
Just change that to capture the folder variable like this...
set subFolder1 to make new folder at targetFolder with properties {name:"01_sub1"}
Then you can put a sub folder into that with...
set anotherSubFolder to make new folder at subFolder1 with properties {name:"another subfolder"}
Note you'll also capture that folder variable so all you need to do to move a file to it is...
move someFile to anotherSubFolder
All I'm showing you is using the same logic you've already used elsewhere in the code.
I have an Applescript that I use to create job folders. The Applescript asks for the project name and the location where the folder will be stored. After inputting the job name and folder location, the script creates the main folder and four subfolders.
Now I would like the script to create numbered subfolders within one of the current subfolders, with a prompt that asks the user how many folders to create. Is that possible?
tell application "Finder"
set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
set loc to choose folder "Choose Parent Folder Location"
set newfoldername to JobName
set newfo to make new folder at loc with properties {name:newfoldername}
make new folder at newfo with properties {name:"Job Materials"}
make new folder at newfo with properties {name:"Previews"}
make new folder at newfo with properties {name:"PSDs"}
make new folder at newfo with properties {name:"VX"}
end tell
set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
set loc to choose folder "Choose Parent Folder Location"
tell application "Finder"
set newfo to make new folder at loc with properties {name:JobName}
make new folder at newfo with properties {name:"Job Materials"}
make new folder at newfo with properties {name:"Previews"}
set targetFolder to make new folder at newfo with properties {name:"PSDs"}
make new folder at newfo with properties {name:"VX"}
end tell
repeat
set subCount to text returned of (display dialog "How many subfolders?" default answer 3)
try
if subCount ≠ "" then
subCount as integer
exit repeat
end if
end try
end repeat
repeat with i from 1 to subCount
tell application "Finder" to make new folder at targetFolder with properties {name:"Subfolder " & i}
end repeat