Using applescript for Find and Replace All in Pages 2.0

i saw that Pages 2.0 is scriptable
i try to create a script for merge use to find and replace all occurence of a certain string using a script but Pages doesn't seems to respond to "Find" even using "System Events"
how can i do to use this function with a script
Thanx for any help
S.B.
ibook G3   Mac OS X (10.4.6)  

OK, here's another example. This one gets the text as a string and uses the offset property to find "[", presuming it to be a merge delimiter. (Pages' text doesn't support "offset of").
One failing of this scheme is that the offsets are incorrect if you have inline objects (pictures, shapes, tables, etc.). While it is probably possible to compensate for them, that's a trickier proposition.
<PRE>-- Example merge replacements:
property mergeText : {"[name]", "John Smith", "[address]", "1234 Anystreet"}
on lookup(mergeWord)
set theCount to count of mergeText
repeat with x from 1 to theCount by 2
if item x of mergeText = mergeWord then
return item (x + 1) of mergeText
end if
end repeat
-- If merge field is not found, delete it (replace it with the empty string)
return ""
end lookup
tell application "Pages"
repeat
tell body text of document 1
-- Get text as a string so that "offset of" can be used.
set allText to it as string
set startOffset to offset of "[" in allText
if (startOffset = 0) then
exit repeat
end if
set endOffset to offset of "]" in allText
select (text from character startOffset to character endOffset)
end tell
set mergeWord to contents of selection
tell me to lookup(mergeWord)
set replacement to result
set selection to replacement
if (replacement is "") then
-- Get rid of extra whitespace (space or return)
-- Do it in a "try" block to handle edge cases at start or end of text.
try
set theSel to (get selection)
set ch1 to character before theSel
set ch2 to character after theSel
if ((ch1 is " " or ch1 is return) and (ch2 is " " or ch2 is return)) then
select character after theSel
delete selection
end if
end try
end if
end repeat
end tell</PRE>
Titanium PowerBook   Mac OS X (10.4.6)  

Similar Messages

  • I do i find and replace all in numbers

    How do I find and replace all.  It is time-consuming to find and replace one entry at a time.

    Works here. As you can see, all three instances were located, in my test.
    Can you think af anything that could be different in your case than in my example?
    Jerry

  • Restrict find and replace to actual page

    I am trying to restrict a "find and replace" to the actual page I am working on in my javascript.
    Is this possible and how can it be done?
    Thanks!

    In scripting, find and replace works on a text object or collection. So
    you would need to get a reference to all the text on your page, and run
    the findText() method on that.
    For instance, in the easy case that there is only one text frame on your
    page, and assuming that the variable myFrame holds that text frame, you
    would simply do:
    myFinds = myFrame.findText();
    (this is assuming you've set all the findTextPreferences as necessary to
    find what you're looking for).
    Ariel

  • Program for find and replace a string in all the reports in a package

    Hello experts,
                        Is there any standard report or transaction provided by SAP which can be used to find a String in all the program in a package ? 
    As per my knowledge there is a program RPR_ABAP_SOURCE_SCAN which can search for a string in a package but this program doesnot support the replacement .
    Any clue in this regard will be helpful.
    Thanks
    Vivek

    Vevek, you are searching for something very very destructive.. do you realize that?
    its better if you could explain us the requirement, by the way for a automated change you need to have INSERT REPORT called inside some program, so start searching that line if you can get it
    else, write a piece of code for it..

  • Using AppleScript to find and move text within a TextEdit document.

    The goal is to do massive restructuring of data within a text edit file that requires a great deal of repetative operations using find text. The process is to use find to locate the item, exit Find at the location in which the item resides, go to the beginning of the line, select the whole line, cut, use find to relocate to the new location, exit Find at the new location, go to the beginning of the line, and paste repeating the process until all the data is restructured. The only problem is that I cannot exit Find using the "Done" button which would put the cursor at the right spot to begin the move. Searching the internet, I found:
         click button "Done" in scroll area 1
    however, that results in:
         error "System Events got an error: Can’t get scroll area 1." number -1728 from scroll area 1
    Searching the internet has not turned up any other method. Anyone that can help?

    You can use find, something like:
    find /dir -name "*.jpg" -exec mv {} dirnew/ \;
    man find for the details...

  • How do I create a multiple find and replace for Excel in AppleScript?

    I have a large dataset in Excel that I have to do a multiple find/replace in (changing USPS state abbreviations to their full names). In searching the Microsoft boards--I was directed to use Applescript, and even the documented help with Excel was recommeding this. Unfortunately, there wasn't much help potinting me in the specific direction I needed. Any ideas on how I should write this script?
    Thanks!

    I'm confused as to why Applescript (or any script would be helpful).
    You'd have to type the abbreviation and the full name into the script, the same as just using Find and Replace All. You wouldn't gain anything by using a script. Is there more to this task than you've let on?
    MacTech has an article on converting from VBA to Applescript, but I'm not sure if it would have any ideas on your specific problem: http://www.mactech.com/vba-transition-guide/index-toc.html

  • "Find and Replace" for field names in a fillable PDF

    Is it possible to do a "Find and Replace" for the field names in a fillable PDF? For example, I have multiple fields that contain the word "Proposed Insured" as part of the field name and would like to find and replace all of them with "Owner". Is there an easy way to do this?

    Not really. Even a script can't just rename a field. It needs to create a
    new field on top of the old one, but then you lose all the associated
    settings, like validation, calculation, format, keystroke, etc.

  • How to find and replace any string between " "

    Hi everyone,
    Here my sample
    String szTest;
    szTest = "Yellow banana";
    szTest = "Blue monkey";
    szTest = "Red mango";
    szTest is only needed when it's in testing progress. Now I want to put all of that in the /*comment*/ so the released program won't run those code any more (but still keep szTest so I can use it for future develop testing).
    So Here what I want after using the Find and Replace Box:
    //String szTest; //Manual
    /*szTest = "Yellow banana";*/ //use find and replace
    /*szTest = "Blue monkey";*/ //use find and replace
    /*szTest = "Red mango";*/ //use find and replace
    I think I can do this with Regular expressions or Wildcards. But I don't know how to find and replace any string between " and ".
    Find: szTest = " ??Any string?? ";
    Replace with: /*szTest = " ??Any string?? ";*/
    Thanks for reading.

    Hi Nathan.j.Smith,
    Based on your issue, I suggest you can try the Joel's suggestion check your issue again. In addition, I find a MSDN document about how to use the Regex.Replace Method to match a regular expression pattern with a specified replacement string,
    maybe you will get some useful message.
    https://msdn.microsoft.com/en-us/library/xwewhkd1(v=vs.110).aspx
    If the above suggestion still could not provide you, could you please tell me what language you use to create the program for finding and replace any string using regular expression so that we will find the correct programming develop forum to support this
    issue?
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Need advanced "Find and Replace" method

    I have bunch of pages need "Find and Replace" work in html
    coding, but I can't use DW's "Find and Replace" function to do with
    it. Here's the sample code:
    quote:
    "<tr valign="top"><td align="center"><a href="
    ../photo/ccg/pages/Columbus Grill
    M_jpg.htm"><img src="../photo/ccg/thumbnails/Columbus
    Grill M_jpg.gif" border="0" onClick="MM_openBrWindow('
    ../photo/ccg/pages/50th Yard
    M_jpg.htm','rr','width=386,height=306')"><br>
    Columbus Grill M</td>
    <td align="center"><a href="
    ../photo/ccg/pages/Columbus Grill
    W_jpg.htm"><img src="../photo/ccg/thumbnails/Columbus
    Grill W_jpg.gif" border="0" onClick="MM_openBrWindow('
    ../photo/ccg/pages/50th Yard
    M_jpg.htm','rr','width=386,height=306')"><br>
    Columbus Grill W</td>
    <td align="center"><a href="
    ../photo/ccg/pages/Cookies Lounge
    M_jpg.htm"><img src="../photo/ccg/thumbnails/Cookies
    Lounge M_jpg.gif" border="0" onClick="MM_openBrWindow('
    ../photo/ccg/pages/50th Yard
    M_jpg.htm','rr','width=386,height=306')"><br>
    Cookies Lounge M</td>
    <td align="center"><a href="
    ../photo/ccg/pages/Cookies Lounge
    W_jpg.htm"><img src="../photo/ccg/thumbnails/Cookies
    Lounge W_jpg.gif" border="0" onClick="MM_openBrWindow('
    ../photo/ccg/pages/50th Yard
    M_jpg.htm','rr','width=386,height=306')"><br>
    Cookies Lounge W</td>
    <td align="center"><a href="
    ../photo/ccg/pages/Corcorans
    M_jpg.htm"><img src="../photo/ccg/thumbnails/Corcorans
    M_jpg.gif" border="0" onClick="MM_openBrWindow('
    ../photo/ccg/pages/50th Yard
    M_jpg.htm','rr','width=386,height=306')"><br>
    Corcorans M</td>
    </tr>"
    You can see I need to use EVERY highlighted code to replace
    each NEXT bolded code, highlighted code are deffirent but bolded
    code are the same. Now I just do it manually, but there are
    thousands of them.
    Is any one has a better method using DW's "Find and Replace"
    function to do this job automatically?

    Using Templates with a 900 page site is a crime against
    humanity. You reach
    the optimal size for Templates between about 50 and 100.
    The error you are getting suggests that there are coding
    errors on the page
    (perhaps even unrelated to ANY DW Template markup). We'd need
    to see the
    page to make progress with what that might be, as Alan says.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "RyanWaters" <[email protected]> wrote in
    message
    news:ggs7fq$gnq$[email protected]..
    >I am a little green to this all. I am trying to find and
    replace a word
    >inside
    > the edit region and Dreamweaver will not change it,
    because it says its
    > inside
    > a locked region, but its a editable region?
    > I have about 900 pages I need to make this change on and
    was relying on
    > the
    > find and replace tool to do that. I tried differn't
    advanced options,
    > nothing
    > seams to change it. I am using cs3. Thanks for any help
    >

  • Find and replace in RTF Template

    Hi,
    I'm using a if statement in my template, but i need to change a value within this statement. It's being used multiple times, therefor it would be easier to do a find and replace, is there a way to do a find and replace within the RTF template? Already openede it in Notepad++, but no luck
    Osman

    I don't think there is a way to find and replace all.. You can view all the code by using Field Browser -> Show All and then replace the code and update one by one from there..
    Thanks,
    Bipuser

  • Find and Replace Subscript

    Hi,
    I am trying to figure out how to find and replace subscripted characters, e.g. H2O (with the "2" subscripted). How is this done?

    Yeah, it has two options. Use formatting (e.g., subscript, but also font, weight, size, leading, colour and whatnot) or do not use formatting -- which does not help, as it is the same as your search string ...
    But fear not. If your "H2O" is the only one, you can do this -- what Peter meant with his two-step.
    1. Search for "H2O" and replace it with "H[ha!]O". Be sure to check both "whole word" and "case sensitive" icons below the replace field. Every "2"
    i inside
    a text "H2O" will be replaced by something unique -- that's what the "[ha!]" should be.
    2. Replace "[ha!]" with "2".
    i Uncheck
    "whole word" and "case sensitive" (because elsewise it won't find anything), and in the Replace Formatting field, select "Subscript" in the Type panel. This 2nd time, you are only replacing the unique string that was put into its unique position in the previous step.
    A 2nd option (one that I don't recommend to freshmen!) is to use the GREP Find-and-replace. This is, in the right hands, an extremely powerful tool, which can
    i search
    for "H2O" and
    i change
    just the "2" part. If I only knew how, off the top of my mind! But, it's neither an easy to remember shortcut, nor perfectly logical, and the 2-step method is.

  • Hello hi, i just won't to ask, if there has been any changes on how to find a stolen phone, did some one come up with a fare and good solution. as it is not fare at all when some one could use it for free and there is a lot of things could be done to this

    hello hi, i just won't to ask, if there has been any changes on how to find a stolen phone, did some one come up with a fare and good solution, new Apps. as it is not fare at all when some one could use it for free and there is a lot of things could be done to this condition, no one seem to care,
    i have a story about my sister, am talking on her behalf, she got stolen her phone at a caffee when she just come from a horeble exam, she was very mad and having haedace for not doing well at the exam, i ask her if we could have coffee before we go home, once she sate; while i was getting the coffee for her, some one snicked to her pocket and took the phone, immidatly she feelt it and went on to searching, but nathing was hopefull. what makes it more heart braking is that she worked day and night just to buy the phone and pay for her books and so on as a student. she use to work 16 houres a day before she had to start school. 8 houres in one place and then to the other place. and she was always demanding for more houres to work; one day her boss saw her on her other job and she was serprised to see her and saied OHhh my God Milly if you work like this, i wonder if you servive, how could you also ask for more houres, My sis had to do it she has no parents or any thing, well the phone was taken after only two months of having it. the sad thing is she stile dream having it even though she can't think of buying againe. well me i have tryed a lot of things but i know some were out there there is a solution for people like this, it is not always fare for some one who has payed up to 800 to just loose his ......  
    Thnks

    I'm sorry, but your sister, unless she had already turned on the "Find my iPhone" feature and the person who took the phone has not disabled it, is out of luck. She should report the theft to local police authorities, including the serial number of her iPhone. While her experience is unfortunate, there are good reasons why Apple cannot do anything else about it.
    I hope she gets her phone back.
    Best of luck.

  • I went on iTUnes after not using it for awhile and all my playlists are gone. How can I find them?

    Hi Apple community ---
    I went on iTunes after not using it for awhile and my old playlists are all gone.  My library seems intact, but I don't have a record of  my playlists, except for what's in my iPod.  I'm afraid to sync them to get the playlists back into my computer, becuase the last time I synced my iphone it erased all my contacts from both my iphone and my computer, and I don't want the sync operation to remove the playlists from the iPod as well. 
    I don't have any music on my iPhone, so the two devices in question are just the iTunes program on the computer (it's a Dell with Windows Vista) and my 160 GB iPod classic. 
    Thanks for your help!!!
    Doc E

    This post may be a clearer place to start...
    tt2

  • How to use Find and Replace for CR or TAB

    How can I use PAGES 'Find and Replace' function to eliminate unwanted carriage returns or Tabs?
    I tried to copy the backwards P and paste into Pages find window, but that doesn't work.
    eMac   Mac OS X (10.4.4)   1 G RAM

    Copying & pasting should work, but it isn't necessary. In the Find & Replace fields hold down the Option key & hit the return or tab key.
    Peggy

  • [Forum FAQ] How to find and replace text strings in the shapes in Excel using Windows PowerShell

    Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
    shapes in Excel Object.
    Since the Excel.Application
    is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
    interact with Excel document.
    The figure below is an excel file:
    Figure 1.
    You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
    $text = “text1”,”text2”,”text3”,”text3”
    $Excel 
    = New-Object -ComObject Excel.Application
    $Excel.visible = $true
    $Workbook 
    = $Excel.workbooks.open("d:\shape.xlsx")      
    #Open the excel file
    $Worksheet 
    = $Workbook.Worksheets.Item("shapes")       
    #Open the worksheet named "shapes"
    $shape = $Worksheet.Shapes      
    # Get all the shapes
    $i=0      
    # This number is used to replace the text in sequence as the variable “$text”
    Foreach ($sh in $shape){
    $sh.TextFrame.Characters().text  
    # Get the textbox in the shape
    $sh.TextFrame.Characters().text = 
    $text[$i++]       
    #Change the value of the textbox in the shape one by one
    $WorkBook.Save()              
    #Save workbook in excel
    $WorkBook.Close()             
    #Close workbook in excel
    [void]$excel.quit()           
    #Quit Excel
    Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
    Besides, we can also find the documents about these methods and properties in MSDN:
    Workbook.Worksheets Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
    Worksheet.Shapes Property:
    http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
    Shape.TextFrame Property:
    http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
    TextFrame.Characters Method (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
    Characters.Text Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
    After running the script above, we can see the changes in the figure below:
    Figure 2.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thank you for the information, but does this thread really need to be stuck to the top of the forum?
    If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
    EDIT: I see this is no longer stuck to the top of the forum, thank you.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

Maybe you are looking for

  • Java Connection Pooling issue with Oracle 10g Express Edition

    Hello I have a Java based web application that uses the Oracle 10g Express Edition database. I am using a connection pool to get connections to the database. I use the NetBeans IDE and run my web application on the bundled Tomcat server(5.5.7) that c

  • Convert word document into .JPG image. Possible?

    Hello I need to convert a word document into a .JPG image... Anyone who can recommend a mac program that can help, or how word can do it for me? Best regards Jesper Pedersen

  • SAPGUI - 'Signature Design', being in different systems, QA, Tst, Prod

    With "Enjoy", I could set my Dev, QA, Tst & Prod to different colors so I can quickly tell what system I am in without looking in lower right corner. I saw a note saying with Signature Design UI, you can't change the color scheme. Is this still true

  • "Open With" drop-down menu has multiple instances of apps

    When I right-click on a file and select "Open With", the resulting drop-down menu contains many, many multiple instances of the same app - five Firefox's, five Quicktime Player's, at least three instances of every relevant app. Why is that happening,

  • Word 2008 & System Log Entries

    Whenever I open Word 2008 there is a flood of never ending entries in System Log as long as Word 2008 is open. This is an example: *Feb 20 14:40:10 Macintosh Microsoft Word[728]: CGBitmapContextGetData: invalid context* *Feb 20 14:40:40: --- last mes