Essentially, I'm trying to make a script that will convert some
highlighted text -- say "we have various Gundam toys here" into an
affiliate link that I need to use to track clicks and subsequent
sales from that click. I've got it working quite well, although the
first grouping in my replace part (where I try to put what I want to
be searched for after the redirected.php?SEARCH/ part) needs some
more work, so that it puts various_Gundam_toys instead of "various
Gundam toys" with the spaces that will break my URL.
The Applescipt I'm using here here:
replace "(.+)" using "<a
href='<http://affiliates.jlist.com/click/19?url=http://www.jlist.com/redirected.php?SEARCH/\\1'>http://affiliates.jlist.com/click/19?url=http://www.jlist.com/redirected.php?SEARCH/\\1'
target='New'>\\1</a>" searching in selection of text window 1
options {search mode:grep, starting at top:false, wrap around:false,
backwards:false, case sensitive:false, match words:false, extend
selection:false}
It currently changes this
We have various Gundam toys here.
into this
We have <a
href='<http://affiliates.jlist.com/click/19?url=http://www.jlist.com/redirected.php?SEARCH/various>http://affiliates.jlist.com/click/19?url=http://www.jlist.com/redirected.php?SEARCH/various
Gundam toys' target='New'>various Gundam toys</a> here.
This won't work though because "various Gundam toys" after my
SEARCH/ part needs to be changed to "various_Gundam_toys."
This is a tricky problem, but it can be worked around by a number of
methods. I would probably do this as a perl filter, but you can do
it using your method from AppleScript using the standard trick of
markers and multiple search and replaces, in this case a loop is
required to handle each space. It is not necessarily the best
solution, but it is easy and it works:
tell application "BBEdit"
replace "(.+)" using "<a
href='http://affiliates.jlist.com/click/19?url=http://www.jlist.com/redirected.php?SEARCH/MARKHERE\\1MARKHERE'
target='New'>\\1</a>" searching in selection of text window 1 options
{search mode:grep, starting at top:false, wrap around:false,
backwards:false, case sensitive:false, match words:false, extend
selection:false}
repeat while 1 = (replace "MARKHERE(.+) (.+)MARKHERE" using
"MARKHERE\\1_\\2MARKHERE" searching in selection of text window 1
options {search mode:grep, starting at top:false, wrap around:false,
backwards:false, case sensitive:false, match words:false, extend
selection:false})
end repeat
replace "MARKHERE(.+)MARKHERE" using "\\1" searching in
selection of text window 1 options {search mode:grep, starting at
top:false, wrap around:false, backwards:false, case sensitive:false,
match words:false, extend selection:false}
end tell
Basically, do your replace as before, but instead of the first \\1,
replace with MARKHERE\\1MARKHERE. The text MARKHERE can be anything,
and the two can be different, as long as they don't match anything in
the search text and they are kept consistent in the following
searches.
Then repeat searching for MARKHERE(.+) (.+)MARKHERE and replacing the
space with _. Repeat until no matches are found.
Then remove the MARKHERE marks and you're done.
Enjoy,
Peter.
--
Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
<http://www.stairways.com/> <http://download.stairways.com/>
--
------------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>