Q: another applescript query
Hi, I have another issue with the script I have been trying to create.
The script seems to run and both dialogues appear and all seems fine but I'm getting this error at the end and the folder structure is only partly created:
"Finder got an error: Can’t make {"Hires", "Lores"} into type Unicode text."
I'll hold my hands up and say I'm winging my way through this and have no real experience of scripting, so any help is greatly appreciated. Script is as follows:
global jobNum
set ThePath to (choose folder)
set jobNum to text returned of (display dialog "Please enter Job Number:" default answer {"RFxxxx"})
set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job Name")
set JobNumName to jobNum & "_" & JobName
makeFolderStructure out of {JobNumName, {jobNum & "_" & "Artwork", {jobNum & "_" & "Resource", jobNum & "_" & "Gone_to_Print", jobNum & "_" & "Copy", jobNum & "_" & "Links", {"eps-tiff", "jpg", "psd", "ai"}, jobNum & "_" & "PDF", {"Hires", "Lores"}}, jobNum & "_" & "MockUps", {jobNum & "_" & "Resource", jobNum & "_" & "Gone_to_Print", jobNum & "_" & "Copy", jobNum & "_" & "Links", {"eps-tiff", "jpg", "psd", "ai"}, jobNum & "_" & "PDF", {"Hires", "Lores"}}, jobNum & "_" & "Design", {jobNum & "_" & "Concepts", {"Workings", {"eps-tiff", "jpg", "psd", "ai"}, "Presentations", "PDF", "Resource"}, jobNum & "_" & "RAD™", {"Workings", {"eps-tiff", "jpg", "psd", "ai"}, "Presentations", "PDF", "Resource"}, jobNum & "_" & "Development", {"Workings", {"eps-tiff", "jpg", "psd", "ai"}, "Presentations", "PDF", "Resource"}, jobNum & "_" & "Finalisation", {"Workings", {"eps-tiff", "jpg", "psd", "ai"}, "Presentations", "PDF", "Resource"}, jobNum & "_" & "Photography", {"Brief", "Templates", "Shoot"}, jobNum & "_" & "Copy"}}} at ThePath
to makeFolderStructure out of someItem at someFolder
set ParentFolder to someFolder
if class of someItem is list then
repeat with AnItem in someItem
if class of AnItem is list then -- add subfolder(s)
makeFolderStructure out of AnItem at someFolder
else -- add a new child folder at the current parent
log AnItem
tell application "Finder"
make new folder at ParentFolder with properties {name:AnItem}
set someFolder to the result as alias
set ParentFolder to someFolder
set aFile to file "RFXXXX_Brief.pdf" of desktop
duplicate {aFile} to someFolder
end tell
end if
end repeat
else -- add a single folder
tell application "Finder"
set fileAlias to file "RFXXXX_Brief.pdf" of ParentFolder
set filePath to fileAlias as text
set TID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set fileName to last text item of filePath
set AppleScript's text item delimiters to "."
set theExtension to last text item of fileName
set fileNamePart1 to text item 1 of fileName
set AppleScript's text item delimiters to "RFXXXX"
set fileNamePart1 to text item 1 of fileNamePart1
set fileNamePart2 to JobNumName
set fileName to fileNamePart1 & fileNamePart2 & "." & theExtension
set AppleScript's text item delimiters to TID
set name of fileAlias to fileName
end tell
tell application "Finder" to make new folder at ParentFolder with properties {name:AnItem}
set someFolder to the result as alias
end if
tell application "Finder" to make new folder at someFolder with properties {name:AnItem}
set ParentFolder to the result as alias
end makeFolderStructure
OS X Mountain Lion (10.8.5), null
Posted on Aug 19, 2016 1:33 AM
Something like this?
set thePath to (choose folder) -- where to place the folder structure
set jobNum to text returned of (display dialog "Please enter Job Number:" default answer "RFxxxx")
set jobName to text returned of (display dialog "Please enter Job Name:" default answer "Job Name")
set jobNumName to jobNum & "_" & jobName
makeFolderStructure out of {jobNumName, {jobNum & "_" & "Artwork", {jobNum & "_" & "Resource", jobNum & "_" & "Gone_to_Print", jobNum & "_" & "Copy", jobNum & "_" & "Links", {"eps-tiff", "jpg", "psd", "ai"}, jobNum & "_" & "PDF", {"Hires", "Lores"}}, jobNum & "_" & "MockUps", {jobNum & "_" & "Resource", jobNum & "_" & "Gone_to_Print", jobNum & "_" & "Copy", jobNum & "_" & "Links", {"eps-tiff", "jpg", "psd", "ai"}, jobNum & "_" & "PDF", {"Hires", "Lores"}}, jobNum & "_" & "Design", {jobNum & "_" & "Concepts", {"Workings", {"eps-tiff", "jpg", "psd", "ai"}, "Presentations", "PDF", "Resource"}, jobNum & "_" & "RAD™", {"Workings", {"eps-tiff", "jpg", "psd", "ai"}, "Presentations", "PDF", "Resource"}, jobNum & "_" & "Development", {"Workings", {"eps-tiff", "jpg", "psd", "ai"}, "Presentations", "PDF", "Resource"}, jobNum & "_" & "Finalisation", {"Workings", {"eps-tiff", "jpg", "psd", "ai"}, "Presentations", "PDF", "Resource"}, jobNum & "_" & "Photography", {"Brief", "Templates", "Shoot"}, jobNum & "_" & "Copy"}}} at thePath
tell application "Finder" -- add (existing) brief file to the structure
set copiedFile to (duplicate (file "RFXXXX_Brief.pdf" of desktop) to folder jobNumName of thePath) -- duplicate
set name of copiedFile to my replaceText((name of copiedFile), "RFXXXX", jobNumName) -- rename
end tell
to makeFolderStructure out of someItem at someFolder -- create a folder structure
(*
someItem defines the structure - nested list items create folders in the previous item:
{"A", {"B",{"D", "E"}, "C"}} = "B" and "C" are created in "A", "D" and "E" are created in "B"
parameters - someItem [list, text]: the folder structure
someFolder [alias]: the destination folder
returns [boolean]: true if successful, false otherwise
*)
set currentParent to someFolder
set completed to true -- this will be the completion result
if class of someItem is list then -- add a list of folders
repeat with anItem in someItem
if class of anItem is list then -- add sub structure(s) to the current parent
makeFolderStructure out of anItem at currentParent
else -- add a single folder to the current parent
tell application "Finder" to try
make new folder at someFolder with properties {name:anItem}
set currentParent to result as alias -- update potential parent
on error -- continue with incomplete result
set completed to false
end try
end if
end repeat
else -- add a single folder
tell application "Finder" to try
make new folder at someFolder with properties {name:someItem}
on error -- continue with incomplete result
set completed to false
end try
end if
return completed
end makeFolderStructure
to replaceText(someText, oldItem, newItem) -- replace all occurances of oldItem with newItem
(*
parameters - someText [text]: the text containing the item(s) to change
oldItem [text, list of text]: the item to be replaced
newItem [text]: the item to replace with
returns [text]: the text with the item(s) replaced
*)
set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, oldItem}
try
set {itemList, AppleScript's text item delimiters} to {text items of someText, newItem}
set {someText, AppleScript's text item delimiters} to {itemList as text, tempTID}
on error errorMessage number errorNumber -- oops
set AppleScript's text item delimiters to tempTID
error errorMessage number errorNumber -- pass it on
end try
return someText
end replaceText
Posted on Aug 19, 2016 7:15 AM