Hello to all,
I’ve put together a script for creating new projects for my work.
I’ve wanted to extend this by adding a bit to copy over a default .xlf file so that I can instantly work from a pre-configured project template (the default .xlf file), but so far I can’t seem to get this to work.
Here is what I have:
-- ------------------------------------------------------------
-- A script to create projects for CafeTran
-- ------------------------------------------------------------
-- ------------------------------------------------------------
-- Sets selection options
-- ------------------------------------------------------------
set option to {"Full project"}
#set option to {"Full project", "Email project", "CafeTran project", "Create XLIFF", "Merge XLIFF"}
-- ------------------------------------------------------------
-- Allows for language/tool selection
-- ------------------------------------------------------------
set theSelection to (choose from list option with prompt "Make Selection:" without multiple selections allowed) as text
-- ------------------------------------------------------------
-- Begin of if-statements for project options
-- ------------------------------------------------------------
if theSelection is "Full project" then
# create project folder
set project_location to choose folder with prompt "Customer documents :" default location "/Users/bowjest/01 Translations/02 Customers"
set project_name to text returned of (display dialog "Job name :" default answer "")
tell application "Finder"
set project_folders to make folder at project_location with properties {name:project_name}
make new folder at project_folders with properties {name:project_name}
#set label index of project_location to 6
#set label index of project_folders to 6
end tell
# create project internal folders
set project_folders_list to {"originals", "mail", "translation"}
repeat with i from 1 to number of items in project_folders_list
set this_item to item i of project_folders_list
set xlf_file to (path to home folder as text) & "01 Translations:02 Customers:01 FIRM:de-gb.template.xlf"
tell application "Finder"
make new folder at project_folders with properties {name:this_item}
copy xlf_file to project_location
#copy file "/Users/bowjest/01 Translations/02 Customers/01 FIRM/cafetran.project.xlf" to project_location
end tell
end repeat
tell application "Finder" to open project_folders
# save job mail to /mail/
# save attachments to /originals/
set mail_data to button returned of (display dialog "Save job data from selected mail ?" buttons {"Yes", "No"} default button {"No"})
if mail_data = "No" then
display alert "Job created"
else
tell application "Mail"
set job to item 1 of (get selection)
set job_info to (get source of job)
set job_name to ((get subject of job) & ".eml")
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set job_name to text items of job_name
set AppleScript's text item delimiters to "_"
set job_name to job_name as rich text
set AppleScript's text item delimiters to ASTID
set job_path to open for access file ((project_folders as rich text) & "mail:" & job_name) with write permission
write job_info to job_path
close access job_path
repeat with original in every mail attachment in job
set original_name to (get name of original)
tell original
set original_path to POSIX path of ((project_folders as rich text) & "originals:" & original_name)
save original in (POSIX file original_path)
end tell
end repeat
end tell
end if
# create project folder
#set parameters_data to ("<?xml version=\"1.0\"?><xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\" xmlns:text=\"urn:cafetran:text\" xmlns:bill=\"urn:cafetran:bill\" xmlns:property=\"urn:cafetran:property\" property:Client=\"FIRM\" text:segment=\"0\"/>")
# write contents to file and close
#set parameters to open for access file ((project_folders as text) & "cafetran.project.xlf") with write permission
#set eof parameters to 0
#write parameters_data to parameters as «class utf8»
#close access parameters
# new CafeTran project is created
tell application "Finder" to open project_folders
#display alert "Job created"
end if
You’ll notice I’ve commented out several things I’ve tried (I’ve still included them here in case I was close in some way).
Also, it would really be great if I could get the section above where I actually try to create the .xlf file itself using AppleScript, but when I do this, CafeTran doesn’t seem to recognise it as valid. The parameters are the same as in the file produced by the system (i.e. CafeTran itself), but I can only guess I’ve somehow failed to include the right defining parameters to make it a valid UTF-8 when the script completes.
Can anyone advise on how I can either:
- Get the above section of the script to create a default .xlf file:
#set parameters_data to ("<?xml version=\"1.0\"?><xliff version=\"1.2\" xmlns=\"urn:oasis:names:tc:xliff:document:1.2\" xmlns:text=\"urn:cafetran:text\" xmlns:bill=\"urn:cafetran:bill\" xmlns:property=\"urn:cafetran:property\" property:Client=\"FIRM\" text:segment=\"0\"/>")
# write contents to file and close
#set parameters to open for access file ((project_folders as text) & "cafetran.project.xlf") with write permission
#set eof parameters to 0
#write parameters_data to parameters as «class utf8»
#close access parameters
or
- Copy a pre-named default .xlf file to the project folder itself. The hierarchy is like this:
Overall project folder (which contains)
Project folder
Mail
Source
Translation
I need to copy the template .xlf file into the “Project folder” that is on the same level with the Mail, Source and Translation folders.
Many thanks,
Bowjest