Need Help with GREP

Hi everyone,
I need some help trying to script a GREP serach.

This is what I have:

tell application "Adobe InDesign CS3"
	activate
	set myDocument to open "Marcus:Working Folder:Griffith Uni:GriffithTemplate.indd"
	
	tell page 1 of myDocument
		set myStory to place "Marcus:Working Folder:Griffith Uni:04-brown.doc" place point {18, 24} with autoflowing without showing options
	end tell
	
	tell active document
		set applied master of page 1 to master spread "B-One Colomn Head"
		--set text frame {18, 24, 63.085, 36.75}
	end tell
	
	tell myDocument
		set colBody to paragraph style "* One Colomn Body" -- get a reference
		set colBody1 to paragraph style "* 1 Section sub head"
		set colBody2 to paragraph style "* 1 Section sub sub head"
		set colBody3 to paragraph style "* One Colomn Main"
		set colBody4 to paragraph style "* One Colomn FirstPara "
		set colBody5 to paragraph style "* One Colomn Drop"
		
		tell parent story of text frame 1 of page 1
			set applied paragraph style to colBody
			set applied paragraph style of paragraph 1 to colBody1
			set applied paragraph style of paragraph 2 to colBody2
			set applied paragraph style of paragraph 3 to colBody1
			set applied paragraph style of paragraph 4 to colBody2
			set applied paragraph style of paragraph 5 to colBody3
			set applied paragraph style of paragraph 6 to colBody4
		end tell
	end tell
	tell application "Adobe InDesign CS3"
		set find grep preferences to nothing
		set change grep preferences to nothing
		set find what of find grep preferences to "(^.)"
		set applied paragraph style of find grep preferences to colBody3
		set change to of change grep preferences to "~P~P$0"
		tell document 1
			change grep
		end tell
		set find grep preferences to nothing
		set change grep preferences to nothing
	end tell
	tell active document
		set applied master of page 2 to master spread "E-BlankPage"
	end tell
	tell application "Adobe InDesign CS3"
		set find grep preferences to nothing
		set change grep preferences to nothing
		set find what of find grep preferences to "\r\r.*\r"
		set change to of change grep preferences to ""
		set applied paragraph style of change grep preferences to colBody5
		tell document 1
			change grep
		end tell
		set find grep preferences to nothing
		set change grep preferences to nothing
	end tell
	tell application "Adobe InDesign CS3"
		set find grep preferences to nothing
		set change grep preferences to nothing
		set find what of find grep preferences to "^.*\r\r"
		set applied paragraph style of find grep preferences to colBody5
		set change to of change grep preferences to ""
		set applied paragraph style of change grep preferences to colBody
		
		tell document 1
			change grep
		end tell
		set find grep preferences to nothing
		set change grep preferences to nothing
	end tell
	
	
	--	tell application "Adobe InDesign CS3"
	--		set find text preferences to nothing
	--		set change text preferences to nothing
	--		set find what of find text preferences to "^p^p"
	--		set applied paragraph style of find text preferences to colBody
	--		set change to of change grep preferences to "^p"
	--		tell document 1
	--			change text
	--		end tell
	--		set find text preferences to nothing
	--		set change text preferences to nothing
	--	end tell
	
end tell

But what I am looking for after it applied the E-Master page
is to search for empty paragraphs (return) and then apply a Paragraph style to the next paragraph after the line space return:

This is what I have now.

Text paragraph
Text paragraph
return
Text Paragraph

This ia what I want

Text paragraph
Text paragraph
return
Text Paragraph but with the new Paragraph Style.

Is is quietly doing my head in…

Thanks Marcus

Arrrggghhh!!!:o:o:o:o:o:o

This is frustrating…

I’ve worked it out.

It appears that Applescript doesn’t like the GREP character \r (return in InDesign CS3)

Once I replaced it with ~b which is essentially the same thing it worked…

in applescript, you need to escape the unix escape .
\r

AppleScript also doesn’t appreciate it when GREP returns no finds. Here’s a generic GREG handler I use. This runs GREP on a file, with a list of things to search for. You should be able to modify it to suit your specific needs.

-- revised GREP routine courtesy of
-- Bruce Phillips of MacScripter
-- http://bbs.applescript.net/viewtopic.php?pid=83871#p83871
--
on grepForString(path_to_grep, search_list)
		
	repeat with current_grep_item in search_list
		try --known bug between AppleScript and GREP where if GREP finds nothing, AppleScript errors-out
			do shell script "/usr/bin/grep --count " & quoted form of current_grep_item & " " & quoted form of POSIX path of path_to_grep
			set grep_result to result
			exit repeat
		on error error_message number error_number
			if error_message is "0" then -- grep didn't find anything
				set grep_result to 0
			else
				-- pass on the error
				error error_message number error_number
			end if
		end try
	end repeat
	
	return {grep_result, contents of current_grep_item}
end grepForString

Thanks Kevin,

That will definatly come in handy.

One thing I’ve noticed in my travels, is there is no list of easy steps for the complete fool, like me.
I posted this on the Adobe InDesign scripting forum as well.

for example:
If you want to make a new document then type “make document”
if you want to change the trim size then type this "set page width to “210mm”
If you want add an amount of page then type this “set pages per document to 10”
If you want to deactivate every thing on you master page…

So you would end up with a script like:


tell application "Adobe InDesign CS3" 
activate 
set Test to make document 
tell document preferences of Test 
set page width to "210mm" 
set page height to "297mm" 
set pages per document to 10 
end tell 
end tell 

This, I think, would save alot of people alot of headaches, if they could just say:
“oh, how do I place picture inside the picture frame?” then they could look up the List and see

To plave an image inside a frame type this…

I did a search for “list of simple applescript commend lines”…didn’t find what I was looking for.