Applescript query....

Hi There,

I’ve put together a script that will list all the names of images within picture boxes in Quark. A report containing these filenames is then created on the desktop.

One thing I’ve noticed with the report is that after the first filename and path I get a blank line after the first item in the list and then all the others are ok.

pic 1
<< The report generated has a space here???
pic 2
pic 3
pic 4

Can anyone tell me why I get this space? And, can anyone tell me how I can get just the filename of the pic and not the path too.

Thanks in advance

Nick

Here’s the code:-

on open (someitems)
	
	set LogFile to a reference to (path to desktop as string) & "FolderContentsList.txt"
	set savedTextItemDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to {return}
	
	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
			
			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 ItemName to (file path of image 1) as text
						
						if ItemName is not equal to "null" then
							
							set picList to (picList & ItemName & return as text)
							
						end if
						
					end tell
					
				end repeat
				
			end repeat
			
			set total to the count of picList
			
			close document 1 saving no
			
		end repeat
		
	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

You’re getting that extra return after the first line because picList is a list the first time through the loop. Here you coerce it to string:

set picList to (picList & ItemName & return as text) 

The first part of the expression in the parentheses is actually list concatenation, so now you’ve got a list of picList and ItemName and return which you then coerce to a string. When you coerce a list to string, the list items have the value of the current text item delimiters inserted between them. In this case, you’ve set the value to ‘return’ earlier. You should be able to work out what’s happening from there. Each subsequent time through the list, picList is a string, and works as you probably expect.

As far as getting the file name of the image, what happens if you change this line:

set ItemName to (file path of image 1) as text

… to this:

set ItemName to (name of image 1) as text

…?

Hi Michael,

Thanks for the help with the script, I amended the script and it’s now ok, the space has gone!

As for the filename instead of the file path I’ve not managed to get this working yet. I’ve changed the code to:-

set ItemName to (name of image 1) as text

However for some reason all I get is a blank report. As yet I not found the error in the script, I’ve had a check in the Quark dictionary and sure enough the ‘name’ attribute is there. This particular version of the script was only a ‘what if’, the file path version was the one I needed. It would be nice to know why the ‘name’ only version of the script is failing.

Thanks again,

Nick