Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting RagTime



Benedikt Quirmbach wrote on Thu, 22 Mar 2007 10:25:07 +0100:

>is there anyone out there who works with RagTime?
>
>If yes, did you ever script search & replace in RagTime?
>Do you have an example on how to do that?

I have RagTime Solo (5.6.4), but only use the spreadsheet. Because of its
complexity and eccentricities, it's not a particularly friendly
application to script. The handler below only works with 'text flow' text
in layout documents, but it may give you somewhere to start.

  on searchAndReplace(searchText, replaceText)
    set searchTextLen to (count searchText)
    set astid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to searchText
    
    tell application "RagTime Solo"
      tell front document
        repeat with i from 1 to (count each text flow)
          set thisText to (text of text flow i) as string as Unicode text
          if (thisText contains searchText) then
            -- Replace the individual search-text occurrences
            -- in the document itself, to preserve style info.
            set b to (count thisText)
            set textItems to reverse of rest of thisText's text items
            repeat with thisTextItem in textItems
              set b to b - (count thisTextItem)
              set a to b - searchTextLen + 1
              set text a thru b of text flow i to replaceText
              set b to a - 1
            end repeat
          end if
        end repeat
      end tell
    end tell
    
    set AppleScript's text item delimiters to astid
  end searchAndReplace
  
  searchAndReplace("Fred", "Aardvark")


NG

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.