I’m totally new to scripting so please forget my ignorance…
I have numerous file (INDESIGN EPS) that i need to change a line of text to another one inside the headers of them.
How can i do that, and which text app (free if possible) can allow me to do this.
Finaly, the script shall be a “when dragged to” kind so when files dragged to it, the text app find/search and replace the text.
Could this be easily done? and which tools do i need…
PS: Snippet of example of code welcome…
Jean-Claude
         
        
          
        
           
           
           
         
         
            
            
          
       
      
      
        
        
          It’s seems to be able to do what i want, but i need something that i can drag n drop file unto, and process them. Something this snippet does not do. Their is also an error when i try to do it with a specific file name… Since i don’t know much about this kind of stuff, i don’t know how to customize it.
JC
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          
--	Save this script as an application.
--
on open (aliasList)
	set textToFind to "Hello World"
	set textReplacement to "Mello Yello"
	repeat with i from 1 to aliasList's length
		set aliasFile to aliasList's item i
		--	Filter out folders:
		--
		if ((aliasFile as string)'s character -1 is not ":") then
			set fileRef to open for access aliasFile with write permission
			try
				set fileContents to read fileRef
				--	note: case-sensitive
				--
				set fileContents to my ReplaceText(fileContents, textToFind, textReplacement)
				--	clear the file's contents
				--
				set eof fileRef to 0
				write fileContents to fileRef
				close access fileRef
			on error e number n from f to t partial result p
				try
					close access fileRef
				end try
				error e number n from f to t partial result p
			end try
		end if
	end repeat
	beep 2 -- all done
end open
on ReplaceText(s, f, r)
	set astids to AppleScript's text item delimiters
	try
		set AppleScript's text item delimiters to f
		set s to s's text items
		set AppleScript's text item delimiters to r
		set s to s as string
		set AppleScript's text item delimiters to astids
		return s
	on error e number n from f to t partial result p
		set AppleScript's text item delimiters to astids
		error e number n from f to t partial result p
	end try
end ReplaceText
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          it is working perfectly…
Way cool! many many thanks!
JC
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          Is it possible also… that a script can read this…
%%BoundingBox: 0 0 810 630
%%HiResBoundingBox: 0 0 810 630
%%CropBox: 9 9 801 621
and copy the CropBox Value (different from each file) and put that number into the BoundingBix and HiResBounding Box…
so the results shall be;
%%BoundingBox: 9 9 801 621
%%HiResBoundingBox: 9 9 801 621
%%CropBox: 9 9 801 621
JC
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          
on open (aliasList)
	repeat with i from 1 to aliasList's length
		set aliasFile to aliasList's item i
		if ((aliasFile as string)'s character -1 is not ":") then
			set fileRef to open for access aliasFile with write permission
			try
				set fileContents to read fileRef
				
				set fileContents to my CustomProcess(fileContents)
				
				set eof fileRef to 0
				write fileContents to fileRef
				close access fileRef
			on error e number n from f to t partial result p
				try
					close access fileRef
				end try
				error e number n from f to t partial result p
			end try
		end if
	end repeat
	beep 2 -- all done 
end open
on CustomProcess(str)
	--	%%BoundingBox: 0 0 810 630
	--	%%HiResBoundingBox: 0 0 810 630
	--	%%CropBox: 9 9 801 621
	set cropBoxLine to GetLineThatStarts(str, "%%CropBox: ")
	--
	--> "%%CropBox: 9 9 801 621"
	set boxBounds to cropBoxLine's text 12 thru -1
	--
	--> "9 9 901 621"
	set str to ¬
		SetLineThatStarts(str, "%%BoundingBox: ", "%%BoundingBox: " & boxBounds)
	set str to ¬
		SetLineThatStarts(str, "%%HiResBoundingBox: ", "%%HiResBoundingBox: " & boxBounds)
	return str as string
end CustomProcess
on GetLineThatStarts(str, startsWith) -- minus the line-ending character
	set x to offset of startsWith in str
	if (x = 0) then
		return missing value
	else
		return (str's text x thru -1)'s paragraph 1
	end if
end GetLineThatStarts
on SetLineThatStarts(str, startsText, newText)
	--	A little hack to determine which line-ending
	--	character str uses. Not a robust solution!
	--
	try
		set ret to str's character (((str's paragraph 1)'s length) + 1)
	on error -- str has no line-ending characters
		set ret to ""
	end try
	set x to offset of startsText in str
	if (x = 0) then return str -- or missing value?
	if (x = 1) then
		if (ret = "") then
			return newText -- only one line was passed
		else
			return newText & ret & str's text from paragraph 2 to paragraph -1
		end if
	else
		set beforeText to str's text 1 thru (x - 1)
		set afterText to (str's text x thru -1)
		try
			set afterText to afterText's text from paragraph 2 to paragraph -1
		on error -- the found line is the last line
			set afterText to ""
		end try
		return beforeText & newText & ret & afterText
	end if
end SetLineThatStarts
Er… I just through this together with minimal testing. Buyer beware…
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          Hey… this seems to work! I have to do a few testing on various file, but this seems to be exactly what i need. You are so great. Thanks!
Jean_Claude