Created
December 9, 2016 04:16
-
-
Save DarthAztek/694a8e3851b578a73d90658ac6580686 to your computer and use it in GitHub Desktop.
InDesign project folder restructure and rename
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set text item delimiters to "." | |
tell application "Finder" | |
--SETUP | |
--get Job code | |
display dialog "Enter Job Code:" default answer "JobCode" | |
set projCode to text returned of result | |
--designate project folder | |
set projectFolder to choose folder with prompt "Select project folder" | |
--ZIP FONTS & RENAME | |
tell application "Finder" | |
set zipSuffix to "_TYPEFACES" | |
--pick font folder | |
set inputFolder to choose folder with prompt "Select font folder to be zipped" | |
tell current application | |
set qpp to quoted form of POSIX path of inputFolder | |
do shell script "cd $(dirname " & qpp & ") | |
zip -r \"$(basename " & projCode & zipSuffix & ").zip\" \"$(basename " & qpp & ")\"" | |
end tell | |
--delete original files | |
delete inputFolder | |
end tell | |
--CREATE NEW PROJECT FOLDERS AND SORT FILES | |
make new folder at projectFolder with properties {name:"HIRES"} | |
--set path to move to HIRES folder | |
set hiFiles to (projectFolder as string) & "HIRES" | |
-- move all files to HIRES | |
set targetFiles to get every item of (entire contents of projectFolder) whose kind ≠ "Folder" | |
--more files into HIRES | |
move targetFiles to hiFiles | |
--remove extraneous folders | |
delete (every folder of projectFolder whose name is not "HIRES") | |
--create previews folder | |
make new folder at projectFolder with properties {name:"PREVIEWS"} | |
--DESIGNATE MAIN MECHANICAL | |
tell application "Finder" | |
--pick the file | |
set mainMech to (choose file with prompt "Select primary mechanical file:") | |
--get the filename to save the extension | |
set mainFNCount to text items of (get name of mainMech) | |
--pull original filename extension | |
if number of mainFNCount is 1 then | |
set mainExt to "" | |
else | |
set mainExt to "." & item -1 of mainFNCount | |
end if | |
--rename file | |
set the name of mainMech to projCode & mainExt as string | |
end tell | |
--DESIGNATE MAIN PDF | |
tell application "Finder" | |
--pick the file | |
set mainPDF to (choose file with prompt "Select primary PDF file:") | |
--get the filename to save the extension | |
set mainFNCount to text items of (get name of mainPDF) | |
--pull original filename extension | |
if number of mainFNCount is 1 then | |
set mainExt to "" | |
else | |
set mainExt to "." & item -1 of mainFNCount | |
end if | |
--rename file | |
set the name of mainPDF to projCode & "_PDF01" & mainExt as string | |
end tell | |
--RENAME ALL _ART FILES IN SEQUENCE | |
tell application "Finder" | |
set all_files to every item of (choose file with prompt "Select all _ART files:" with multiple selections allowed) as list | |
--add in the support filename suffix | |
set artSuffix to "_ART" | |
--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file. | |
--the 'index' number is required for the sequential renaming of files | |
repeat with index from 1 to the count of all_files | |
--using our index, we select the appropriate file from our list | |
set this_file to item index of all_files | |
set file_name_count to text items of (get name of this_file) | |
--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later | |
if index is less than 10 then | |
set index_prefix to "0" | |
else | |
set index_prefix to "" | |
end if | |
--lets check if the current file from our list (based on index-number) has even any file-extension | |
if number of file_name_count is 1 then | |
--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present. | |
set file_extension to "" | |
else | |
--re-add the original file-extension after changing the name of the file | |
set file_extension to "." & item -1 of file_name_count | |
end if | |
--rename file, add the sequential number from 'index' and add the file-extension to it | |
set the name of this_file to projCode & artSuffix & index_prefix & index & file_extension as string | |
end repeat | |
display notification "File Rename Complete " & index & " files with '" & projCode & "' for you." | |
end tell | |
--RENAME ALL _BIT FILES IN SEQUENCE | |
tell application "Finder" | |
set all_files to every item of (choose file with prompt "Select all _BIT files:" with multiple selections allowed) as list | |
--add in the support filename suffix | |
set bitSuffix to "_BIT" | |
--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file. | |
--the 'index' number is required for the sequential renaming of files | |
repeat with index from 1 to the count of all_files | |
--using our index, we select the appropriate file from our list | |
set this_file to item index of all_files | |
set file_name_count to text items of (get name of this_file) | |
--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later | |
if index is less than 10 then | |
set index_prefix to "0" | |
else | |
set index_prefix to "" | |
end if | |
--lets check if the current file from our list (based on index-number) has even any file-extension | |
if number of file_name_count is 1 then | |
--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present. | |
set file_extension to "" | |
else | |
--re-add the original file-extension after changing the name of the file | |
set file_extension to "." & item -1 of file_name_count | |
end if | |
--rename file, add the sequential number from 'index' and add the file-extension to it | |
set the name of this_file to projCode & bitSuffix & index_prefix & index & file_extension as string | |
end repeat | |
display notification "File Rename Complete " & index & " files with '" & projCode & "' for you." | |
end tell | |
--RENAME ALL _LYRD FILES IN SEQUENCE | |
tell application "Finder" | |
set all_files to every item of (choose file with prompt "Select all _LYRD files:" with multiple selections allowed) as list | |
--add in the support filename suffix | |
set lyrdSuffix to "_LYRD" | |
--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file. | |
--the 'index' number is required for the sequential renaming of files | |
repeat with index from 1 to the count of all_files | |
--using our index, we select the appropriate file from our list | |
set this_file to item index of all_files | |
set file_name_count to text items of (get name of this_file) | |
--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later | |
if index is less than 10 then | |
set index_prefix to "0" | |
else | |
set index_prefix to "" | |
end if | |
--lets check if the current file from our list (based on index-number) has even any file-extension | |
if number of file_name_count is 1 then | |
--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present. | |
set file_extension to "" | |
else | |
--re-add the original file-extension after changing the name of the file | |
set file_extension to "." & item -1 of file_name_count | |
end if | |
--rename file, add the sequential number from 'index' and add the file-extension to it | |
set the name of this_file to projCode & lyrdSuffix & index_prefix & index & file_extension as string | |
end repeat | |
display notification "File Rename Complete " & index & " files with '" & projCode & "' for you." | |
end tell | |
--RENAME ALL _IL FILES IN SEQUENCE | |
tell application "Finder" | |
set all_files to every item of (choose file with prompt "Select all _IL files:" with multiple selections allowed) as list | |
--add in the support filename suffix | |
set ilSuffix to "_IL" | |
--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file. | |
--the 'index' number is required for the sequential renaming of files | |
repeat with index from 1 to the count of all_files | |
--using our index, we select the appropriate file from our list | |
set this_file to item index of all_files | |
set file_name_count to text items of (get name of this_file) | |
--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later | |
if index is less than 10 then | |
set index_prefix to "0" | |
else | |
set index_prefix to "" | |
end if | |
--lets check if the current file from our list (based on index-number) has even any file-extension | |
if number of file_name_count is 1 then | |
--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present. | |
set file_extension to "" | |
else | |
--re-add the original file-extension after changing the name of the file | |
set file_extension to "." & item -1 of file_name_count | |
end if | |
--rename file, add the sequential number from 'index' and add the file-extension to it | |
set the name of this_file to projCode & ilSuffix & index_prefix & index & file_extension as string | |
end repeat | |
display notification "File Rename Complete " & index & " files with '" & projCode & "' for you." | |
end tell | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tripped over myself on this one. Is there a way I can have it "skip" a step if a certain file type in the script ("_ART," "BIT", etc) is not in the project? Cancelling out midway through terminates the script entirely and I'd like to give the user a choice. I'm also wondering if between each prompt to pick a folder, if it can automatically start at the projectFolder level? I know this script is verbose, but this is my first attempt at working in AppleScript. Thanks!