I’ve put together a script (with the help of previous posters) to fill in the information in a slug in Illustrator. It all works perfectly apart from the section that gets the file version. The section is commented in the script. This works if you run the script more than once on any particular document!
Any ideas?
The full version of the script posted here will put information into named boxes in and illustrator document. But to see the error you only need to look in the Events and Replies of Applescript Editor and see that the information does not go in first time round.
-- captures the user's first name from the system for use in dialog boxes
set myName to (long user name of (system info))
set sp to (offset of " " in myName)
set myFirstName to text 1 thru (sp - 1) of myName
-- captures the user's short name from the system for use in the slug
set myShortName to (short user name of (system info))
set myInitials to text 1 thru 2 of myShortName
tell application "Adobe Illustrator" to set myDocCount to count of documents
if myDocCount > 0 then
tell application "Adobe Illustrator"
try
set myPath to file path of document 1 as alias -- if the document is not saved this will cause an error
on error
display dialog "You haven't saved document yet " & myFirstName & "." buttons {"Cancel", "Save"} default button 2
-- brings up Save As dialog box
tell application "System Events" to tell process "Adobe Illustrator"
click menu item "Save As..." of menu 1 of menu bar item "File" of menu bar 1
tell application "Finder"
set filesavepath to "/Volumes/Acorn Studio/Client WIP"
end tell
delay 0.2
tell window "Save As"
keystroke "g" using {command down, shift down}
repeat until exists sheet 1
delay 0.5
end repeat
tell sheet 1
keystroke filesavepath
click button "Go"
end tell
end tell
end tell
-- end Save As dialog box
return
end try
set myFile to name of document 1
set myFolder to myPath as string
-- this section to get the version of the file causes an error first time round
--try
tell application "Finder"
set myFileVersion to version of myPath as text
end tell
set AppleScript's text item delimiters to "Created"
set myFileVersion to text item 1 of myFileVersion
if myFileVersion is "Saved As v.14 " then
set myFileVersion to "Illustrator CS4"
else if myFileVersion is "Saved As v.13 " then
set myFileVersion to "Illustrator CS3"
else if myFileVersion is "Saved As v.12 " then
set myFileVersion to "Illustrator CS2"
end if
set AppleScript's text item delimiters to {""}
--end try
-- end of error section
set AppleScript's text item delimiters to ":"
set clientFolder to text item 3 of myFolder -- always picks out the client folder provided the file is saved in Client WIP
set AppleScript's text item delimiters to {""}
if clientFolder contains "_" then
set clientFolder to my cleanName(clientFolder) -- to format the client names properly
else
set clientFolder to clientFolder
end if
tell application "Finder"
set myDate to (current date) as string
end tell
set myDate to (word 2 of myDate) & " " & (text 1 thru 3 of word 3 of myDate) & " " & (word 4 of myDate) as string
set myRevised to myDate -- temporary until old artwork slugs are out of the system
-- checks for the correctly named frames and then populates with the correct information
if exists (text frame "titleblock-software" of document 1) then
set contents of text frame "titleblock-software" of document 1 to myFileVersion
end if
if exists (text frame "titleblock-client" of document 1) then
set contents of text frame "titleblock-client" of document 1 to clientFolder
end if
if exists (text frame "titleblock-file" of document 1) then
set contents of text frame "titleblock-file" of document 1 to myFile
end if
if exists (text frame "titleblock-path" of document 1) then
set contents of text frame "titleblock-path" of document 1 to myPath as string
end if
if exists (text frame "titleblock-date" of document 1) then -- the aim is to use this only eventually
set contents of text frame "titleblock-date" of document 1 to myDate
end if
if exists (text frame "titleblock-revised" of document 1) then -- temporary until old artwork slugs are out of the system
set contents of text frame "titleblock-revised" of document 1 to myRevised
end if
if exists (text frame "titleblock-editor" of document 1) then
set contents of text frame "titleblock-editor" of document 1 to myInitials
end if
if exists (text frame "titleblock-version" of document 1) then
set versionCount to get contents of text frame "titleblock-version" of document 1
set versionCount to (versionCount + 1)
set contents of text frame "titleblock-version" of document 1 to versionCount
-- end populating named frames
end if
end tell
end if
-- this handler converts every 'odd' character to an underscore, modify as needed
on cleanName(newName)
set chars to every character of newName
repeat with i from 1 to length of chars
if item i of chars as text is equal to "_" then
set item i of chars to " "
end if
end repeat
return every item of chars as string
end cleanName
Model: 2 x 2.8 GHz Quad-Core Intel Xeon
AppleScript: 2.1.2
Browser: Firefox 3.6.14
Operating System: Mac OS X (10.6)