Record Macro

852 views
Skip to first unread message

Kent

unread,
Mar 18, 2009, 5:24:08 PM3/18/09
to BBEdit Talk
Is it possible to record and then playback a macro? It would be
something like:

-- start record --
go to end of line
delete 5 chars
paste some text
go to next line
-- end record --

I've done this with other editors, I just haven't found a way in
BBEdit yet.

Thanks

Bill Hernandez

unread,
Mar 19, 2009, 9:34:43 PM3/19/09
to bbe...@googlegroups.com
On Mar 18, 2009, at 4:24 PM, Kent wrote:

Kent,

This will do the trick.
Save the script, drop it in the BBEdit scripts folder, assign it a key
equivalent, and that should do it..

Best Regards,

Bill Henandez
Plano, Texas

-- +---------+---------+---------+---------+---------+---------+
-- [ BEGIN ] scriptname : replace_last_N_chars.scpt
-- +---------+---------+---------+---------+---------+---------+
on run

set no_of_chars to 5 -- change this value if you need to...

tell application "BBEdit"
activate
set clip to contents of current clipboard

set str to "What value would you like to use to replace the last ( "
& no_of_chars & " ) characters of each line ?"
try
set theResult to display dialog str default answer clip
set clip to text returned of theResult
set the current clipboard to clip
on error
display dialog "Cancelled..." buttons {"OK"} default button {"OK"}
giving up after 1
return
end try

tell text 1 of text document 1

select insertion point before character 1
set no_of_lines to count lines
set n to 0
repeat no_of_lines times
set n to n + 1
try
select characters -(no_of_chars) through -1 of line n
set contents of the selection to clip
on error

end try
end repeat
end tell
end tell
end run
-- +---------+---------+---------+---------+---------+---------+
-- [ _END_ ] scriptname : replace_last_N_chars.scpt
-- +---------+---------+---------+---------+---------+---------+

Bill Hernandez

unread,
Mar 19, 2009, 9:48:58 PM3/19/09
to bbe...@googlegroups.com
On Mar 18, 2009, at 4:24 PM, Kent wrote:

Here's an alternate way using FIND/REPLACE (CMD-F):

You can do a find and replace (CMD-F)
[x] Use Grep
[x] Start Top
[x] Case sensitive

FIND : ^([^\r]+)([ \S]{5,5})
REPLACE : \1REPLACED_FIVE_CHARS

where REPLACED_FIVE_CHARS is the tesxt you want to use to replace

we had requests for searching
for tickets against specific
ports before.
Now I created a report in Trac which allows
you to do that. It searches
the "Port" field which can be set
when creating tickets. This being
said, please always fill the field
with the appropriate value!

As you can see below...

we had requests for searcREPLACED_FIVE_CHARS
for tickets against speREPLACED_FIVE_CHARS
ports beREPLACED_FIVE_CHARS
Now I created a report in Trac which alREPLACED_FIVE_CHARS
you to do that. It seaREPLACED_FIVE_CHARS
the "Port" field which can beREPLACED_FIVE_CHARS
when creating tickets. This REPLACED_FIVE_CHARS
said, please always fill the fREPLACED_FIVE_CHARS
with the appropriate vREPLACED_FIVE_CHARS

I thought of this after sending the AppleScript. Grep is far more
flexible on the run

Best Regards Again,

Best Regards,

Bill Henandez
Plano, Texas

Peter N Lewis

unread,
Mar 20, 2009, 9:50:13 PM3/20/09
to bbe...@googlegroups.com

Bill has suggested some good solutions.

A grep search and replace is the obvious one, I would just use:

Search for: .....$
Replace with: <paste some text>

This would be a good solution.

However you can do what you describe using Keyboard Maestro,
especially the Quick Record macro can be very useful for this:

Type Quick Record Macro hot key
Type command-right arrow
Type delete five times
Type command-V
Type down arrow (to get to the next line)
Type Quick Record Macro hot key

Then just press the Quick Record Macro activator key for each line.

For small numbers of lines (say around ten) this is often faster than
figuring out the grep expression, and for cases where you want to
control which lines it acts on this will be a better solution. But
for acting on large numbers of lines a grep solution will be better.

Enjoy,
Peter.

--
Run macros from your iPhone with Keyboard Maestro Control!
or take a break with Derzle for your iPhone

Keyboard Maestro <http://www.keyboardmaestro.com/> Macros for your Mac
Aragom Space War <http://www.stairways.com/iphone/aragom> Don't get killed!
Derzle <http://www.stairways.com/iphone/derzle> Enjoy a relaxing puzzle.
<http://www.stairways.com/> <http://download.stairways.com/>

Semper Fidelis

unread,
Mar 20, 2009, 11:04:53 PM3/20/09
to bbe...@googlegroups.com
Or, more compactly:

Search For: .{5}$

Replace With: <paste_with_whatever_text>

Bill Hernandez

unread,
Mar 21, 2009, 1:20:40 AM3/21/09
to bbe...@googlegroups.com

On Mar 20, 2009, at 10:04 PM, Semper Fidelis wrote:

> Or, more compactly:
>
> Search For: .{5}$
>
> Replace With: <paste_with_whatever_text>


It doesn't get any easier than that...

Good Show !

Bill Hernandez
Plano, Texas

Reply all
Reply to author
Forward
0 new messages