Hi there,
I’ve managed to create a script that almost does what I need but I’m not sure what would be the best way to tackle one last bit.
Basically, I have a Quark document that contains several pages. Each page has several pic boxes with pics in.
I’ve written a script that goes through the Quark document and creates a list of the pictures used within the document.
It only creates a list of the picture names that start with a number which is a unique id.
For example in the list below it would only make a list containing three of the four files, the file ‘abcd_pic3’ would not be included.
1234_pic1
1234i_pic2
abcd_pic3
5678_pic4
The list generated looks like this:-
1234,1234_pic1
1234,1234i_pic2
5678,5678_pic4
The numbers from the front of filename are listed and then the actual full filename seperated by a comma.
Notice in the first list there are two filenames that start with 1234 the difference being the ‘i’ after the number.
Here’s the question - when this occurs I want to take that filename and put it on the same line as the number 1234.
So the final list generated would look like:-
1234,1234_pic1,1234i_pic2
5678,5678_pic4
rather than:-
1234,1234_pic1
1234,1234i_pic2
5678,5678_pic4
Can anyone suggest the best way to go about this? I obviously need to look to see what the next filename is, so if the cuurent id is 1234 I need to look to the next filename to see if that starts with 1234. If it does I need to add it to the last line. I’ve done some work with Coldfusion lists and with that I have a List Append command, is there something similar with Applescript.
Any help would be appreciated, thanks in advance,
Nick
P.S. I know there are probably many ways my code could be cleaned up, I’m still a bit of a newbie to this.
Here’s the code:-
on open (someitems)
set LogFile to a reference to (path to desktop as string) & "PicList_NamesOnly.txt"
set savedTextItemDelimiters to AppleScript's text item delimiters
set filecount to 0
set picList to {}
tell application "QuarkXPress"
activate
repeat with theitem in someitems
open theitem remap fonts no use doc prefs yes
get the count of every page in document 1
set pagecount to the result
set filename to (name of (get info for theitem))
set picList to (picList & "FILENAME:- " & filename & return as text)
repeat with pc from 1 to pagecount -- page loop
set picBoxCount to the count of every picture box of page pc of document 1 -- pic box loop
repeat with i from 1 to picBoxCount
tell picture box i of page pc of document 1
set fn to (file path of image 1) as text
if fn is not equal to "«class null»" then
set AppleScript's text item delimiters to ":"
set ItemName to fn's text items -1 thru -1
set AppleScript's text item delimiters to {""}
set textItemName to ItemName as text
-- ---------------------------------------------------------------------
set char_count to 1
set numChars to ""
set char to character char_count of textItemName
set av to ASCII number of char
repeat while av is not less than 48 and av is not greater than 57
set numChars to numChars & (character char_count of textItemName)
set char_count to char_count + 1
set char to character char_count of textItemName
set av to ASCII number of char
end repeat
-- ---------------------------------------------------------------------
if numChars is not equal to "" then
set picList to picList & numChars & "," & ItemName & return as text
end if
end if
end tell
end repeat
end repeat
set picList to (picList & return as text)
set total to the count of picList
close document 1 saving no
set filecount to filecount + 1
end repeat
set picList to picList & "Count:- " & filecount & return as text
end tell
try
open for access file LogFile with write permission
set eof of file LogFile to 0
write picList to file LogFile
close access file LogFile
on error errText number errNum
close access file LogFile
display dialog errText
end try
set AppleScript's text item delimiters to savedTextItemDelimiters
end open