Welcome to MacBoardz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Applescript to work with text. I'm stuck.

 
   Macintosh computer (Home) -> Apple Scripts RSS
Next:  Problem with Cron?  
Author Message
Fuddled

External


Since: May 04, 2008
Posts: 5



(Msg. 1) Posted: Sun May 04, 2008 9:41 am
Post subject: Applescript to work with text. I'm stuck.
Archived from groups: alt>comp>lang>applescript (more info?)

Hi nice peoples

I'm working in BBEdit, preparing academic documents to be browser-read,
and I'd like to reproduce a script I have written for FileMaker Pro,
which places tags round either side of a selection.

e.g. if I want to markup a word/phrase for italics, in FileMaker I can
easily write a script that copies

selection

and replaces it with

<i>selection</i>

Sole purpose: to do the job quicker than manually copy-pasting the
front tag, then pasting the end tag, backing up 2 spaces and inserting
the /. Time after time.

Nothing fancy. I thought it would be simple to reproduce this tool in
Applescript for use in BBEdit, but I'm stuck!! I've gone googling for
help, and now I'm even more confused than I was before. I got some of
it to work, but not the whole trick.

Maybe I should buy a book, but the one I found in a library doesn't
seem to provide help in this area. There doesn't seem to be any guide
or whatever that suits my limited CODING expertise. Perhaps Applescript
isn't designed for this sort of thing?

So I'm simply asking you guys who DO understand:

1) can I do this? and how?

AND

2) will a book like Applescript for Dummies cover this sort of thing?

All this has sure made me feel like a dummy, and I hope some kind
person has the patience to help me out.

Thanks in (hopeful) anticipation.


Fuddled.

 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
J. Stewart

External


Since: Jul 19, 2006
Posts: 43



(Msg. 2) Posted: Sun May 04, 2008 9:41 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2008-05-04 05:41:44 -0400, Fuddled said:

> Hi nice peoples
>
> I'm working in BBEdit, preparing academic documents to be browser-read,
> and I'd like to reproduce a script I have written for FileMaker Pro,
> which places tags round either side of a selection.
>
> e.g. if I want to markup a word/phrase for italics, in FileMaker I can
> easily write a script that copies
>
> selection
>
> and replaces it with
>
> <i>selection</i>
>
> Sole purpose: to do the job quicker than manually copy-pasting the
> front tag, then pasting the end tag, backing up 2 spaces and inserting
> the /. Time after time.
>
> Nothing fancy. I thought it would be simple to reproduce this tool in
> Applescript for use in BBEdit, but I'm stuck!! I've gone googling for
> help, and now I'm even more confused than I was before. I got some of
> it to work, but not the whole trick.
>
> Maybe I should buy a book, but the one I found in a library doesn't
> seem to provide help in this area. There doesn't seem to be any guide
> or whatever that suits my limited CODING expertise. Perhaps Applescript
> isn't designed for this sort of thing?
>
> So I'm simply asking you guys who DO understand:
>
> 1) can I do this? and how?
>
> AND
>
> 2) will a book like Applescript for Dummies cover this sort of thing?
>
> All this has sure made me feel like a dummy, and I hope some kind
> person has the patience to help me out.
>
> Thanks in (hopeful) anticipation.

Have you tried something like this?

--> Cut <--
tell application "BBEdit"
set selection to "<i>" & (get selection) & "</i>"
end tell
--> Cut <--

This works fine in TextWrangler which is almost identical to BBEdit
where scripting is concerned.
>
--
Use ROT 13 on email address for replies to sender

 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
J. Stewart

External


Since: Jul 19, 2006
Posts: 43



(Msg. 3) Posted: Sun May 04, 2008 9:41 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2008-05-04 05:41:44 -0400, Fuddled said:

> 2) will a book like Applescript for Dummies cover this sort of thing?
>
> All this has sure made me feel like a dummy, and I hope some kind
> person has the patience to help me out.

Sorry I didn't answer #2 in the original answer.

Usually you won't find detailed application scripting commands in a
book like that one unless the author just happened to pick it for an
example. They tend to use applications that come with a clean OS
install, TextEdit for instance. Where you can get this sort of
information is the application's scripting dictionary. Just drag the
app's icon to the Script Editor icon in the dock or select the "Open
Dictionary" command in Script Editor's "File" menu and choose it from
the resulting list.

If you are looking for a place to start with AppleScript then the
Applescript Language Guide is it. Its located here -
<http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html>

I'd

suggest you download it in the available PDF format. For a more
in-depth look I'd suggest Matt Neuburg's "Applescript: The Definitive
Guide" 2nd edition from O'Reilly press. Amazon.com has it available.
--
Use ROT 13 on email address for replies to sender
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Dave Balderstone

External


Since: Mar 21, 2006
Posts: 1688



(Msg. 4) Posted: Sun May 04, 2008 9:41 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 5) Posted: Sun May 04, 2008 2:08 pm
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Fuddled wrote:

> I'm working in BBEdit, preparing academic documents to be browser-read,
> and I'd like to reproduce a script I have written for FileMaker Pro,
> which places tags round either side of a selection.
>
> e.g. if I want to markup a word/phrase for italics, in FileMaker I can
> easily write a script that copies
>
> selection
>
> and replaces it with
>
> <i>selection</i>

Why use BBEdit at all? AppleScript can read text files and write text
files. And AppleScript can replace text in strings. So you don't even
need to involve BBEdit.

Try this script on for size:

<http://jollyroger.kicks-ass.org/convert/Convert.applescript>

I packed it up in a ZIP archive if you'd like to download the script and
run it:

<http://jollyroger.kicks-ass.org/convert/Convert.zip>

Enjoy!

--
Please send all responses to the relevant news group. E-mail sent to
this address may be devoured by my very hungry SPAM filter. I do not
read posts from Google Groups. Use a real news reader if you want me to
see your posts.

JR
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Fuddled

External


Since: May 04, 2008
Posts: 5



(Msg. 6) Posted: Mon May 05, 2008 2:28 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , J. Stewart
wrote:

> On 2008-05-04 05:41:44 -0400, Fuddled said:
>
> > Hi nice peoples
> >
> > I'm working in BBEdit, preparing academic documents to be browser-read,
> > and I'd like to reproduce a script I have written for FileMaker Pro,
> > which places tags round either side of a selection.
> >
> > e.g. if I want to markup a word/phrase for italics, in FileMaker I can
> > easily write a script that copies
> >
> > selection
> >
> > and replaces it with
> >
> > <i>selection</i>
> >
> > Sole purpose: to do the job quicker than manually copy-pasting the
> > front tag, then pasting the end tag, backing up 2 spaces and inserting
> > the /. Time after time.
> >
> > Nothing fancy. I thought it would be simple to reproduce this tool in
> > Applescript for use in BBEdit, but I'm stuck!! I've gone googling for
> > help, and now I'm even more confused than I was before. I got some of
> > it to work, but not the whole trick.
> >
> > Maybe I should buy a book, but the one I found in a library doesn't
> > seem to provide help in this area. There doesn't seem to be any guide
> > or whatever that suits my limited CODING expertise. Perhaps Applescript
> > isn't designed for this sort of thing?
> >
> > So I'm simply asking you guys who DO understand:
> >
> > 1) can I do this? and how?
> >
> > AND
> >
> > 2) will a book like Applescript for Dummies cover this sort of thing?
> >
> > All this has sure made me feel like a dummy, and I hope some kind
> > person has the patience to help me out.
> >
> > Thanks in (hopeful) anticipation.
>
> Have you tried something like this?
>
> --> Cut <--
> tell application "BBEdit"
> set selection to "<i>" & (get selection) & "</i>"
> end tell
> --> Cut <--
>
> This works fine in TextWrangler which is almost identical to BBEdit
> where scripting is concerned.
> >

Yes I have tried it and IT WORKS!! Yeeehay! Many thanks J, and now I'll
set to work on attempting to reverse-engineer an understanding of WHY
it works!

That's excellent - you made my morning!

(not quite so) Fuddled Smile
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Michelle Steiner

External


Since: Jul 15, 2003
Posts: 3627



(Msg. 7) Posted: Mon May 05, 2008 2:28 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
Fuddled

External


Since: May 04, 2008
Posts: 5



(Msg. 8) Posted: Mon May 05, 2008 2:38 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , J. Stewart
wrote:

> On 2008-05-04 05:41:44 -0400, Fuddled said:
>
> > 2) will a book like Applescript for Dummies cover this sort of thing?
> >
> > All this has sure made me feel like a dummy, and I hope some kind
> > person has the patience to help me out.
>
> Sorry I didn't answer #2 in the original answer.
>
> Usually you won't find detailed application scripting commands in a
> book like that one unless the author just happened to pick it for an
> example. They tend to use applications that come with a clean OS
> install, TextEdit for instance. Where you can get this sort of
> information is the application's scripting dictionary. Just drag the
> app's icon to the Script Editor icon in the dock or select the "Open
> Dictionary" command in Script Editor's "File" menu and choose it from
> the resulting list.
>
> If you are looking for a place to start with AppleScript then the
> Applescript Language Guide is it. Its located here -
>
> <http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLa
> ngGuide/introduction/ASLR_intro.html>
>
> I'd
>
> suggest you download it in the available PDF format. For a more
> in-depth look I'd suggest Matt Neuburg's "Applescript: The Definitive
> Guide" 2nd edition from O'Reilly press. Amazon.com has it available.

Yes, if I had some $pare cash I'd buy Matt's book. Thanks for the
advice re the Dummies book, that's just as I suspected. I wish those
Scripting Dictionaries had examples. Maybe it's time I put all other
work aside and concentrated on breaking through this block. I'm a
Humanities type and quite lacking in the approriate methodologies for
codes and (machine) languages.

I really appreciate your assistance here.

F
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Fuddled

External


Since: May 04, 2008
Posts: 5



(Msg. 9) Posted: Mon May 05, 2008 2:44 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , Jolly
Roger wrote:

> In article ,
> Fuddled wrote:
>
> > I'm working in BBEdit, preparing academic documents to be browser-read,
> > and I'd like to reproduce a script I have written for FileMaker Pro,
> > which places tags round either side of a selection.
> >
> > e.g. if I want to markup a word/phrase for italics, in FileMaker I can
> > easily write a script that copies
> >
> > selection
> >
> > and replaces it with
> >
> > <i>selection</i>
>
> Why use BBEdit at all? AppleScript can read text files and write text
> files. And AppleScript can replace text in strings. So you don't even
> need to involve BBEdit.

As I'm building HTML pages, I can't think of anything more friendly.
All those pretty colours are just the thing for an Arts faculty.

I'm working on a whole collection of documents to present via browser,
consistently displayed, clean-and-simple, CSS etc., hence BBE.

>
> Try this script on for size:
>
> <http://jollyroger.kicks-ass.org/convert/Convert.applescript>
>
> I packed it up in a ZIP archive if you'd like to download the script and
> run it:
>
> <http://jollyroger.kicks-ass.org/convert/Convert.zip>
>
> Enjoy!

Many thanks, Mr Roger, I'll try this.
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 10) Posted: Mon May 05, 2008 2:44 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Fuddled wrote:

> In article , Jolly
> Roger wrote:
>
> > In article ,
> > Fuddled wrote:
> >
> > > I'm working in BBEdit, preparing academic documents to be browser-read,
> > > and I'd like to reproduce a script I have written for FileMaker Pro,
> > > which places tags round either side of a selection.
> > >
> > > e.g. if I want to markup a word/phrase for italics, in FileMaker I can
> > > easily write a script that copies
> > >
> > > selection
> > >
> > > and replaces it with
> > >
> > > <i>selection</i>
> >
> > Why use BBEdit at all? AppleScript can read text files and write text
> > files. And AppleScript can replace text in strings. So you don't even
> > need to involve BBEdit.
>
> As I'm building HTML pages, I can't think of anything more friendly.
> All those pretty colours are just the thing for an Arts faculty.
>
> I'm working on a whole collection of documents to present via browser,
> consistently displayed, clean-and-simple, CSS etc., hence BBE.

That may be, but in actuality, you are automating a search and replace
operation that has nothing at all to do with BBEdit. Sending commands to
BBEdit will only slow things down, because BBEdit will have to draw each
change in selection and so on to the screen. The job you are actually
doing has little to do with BBEdit - so why complicate things?

> > Try this script on for size:
> >
> > <http://jollyroger.kicks-ass.org/convert/Convert.applescript>
> >
> > I packed it up in a ZIP archive if you'd like to download the script and
> > run it:
> >
> > <http://jollyroger.kicks-ass.org/convert/Convert.zip>
> >
> > Enjoy!
>
> Many thanks, Mr Roger, I'll try this.

You're welcome.

--
Please send all responses to the relevant news group. E-mail sent to
this address may be devoured by my very hungry SPAM filter. I do not
read posts from Google Groups. Use a real news reader if you want me to
see your posts.

JR
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Jerry Kindall

External


Since: Jul 09, 2003
Posts: 853



(Msg. 11) Posted: Mon May 05, 2008 7:54 pm
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , Jolly
Roger wrote:

> The point is if you have a collection of files and you want to use
> AppleScript to change some text in them, no text editor is needed. If
> you do this in pure AppleScript instead, it's quick as lightning. You
> said you'd try the script I sent you - did you try it? You'll find it's
> faster than any script that uses a BBEdit window to change text. This is
> because writing the AppleScript to control the text editor will only
> slow things down - it takes time for the text editor to draw changes to
> the window and so on.

I think you've wandered off into the weeds a little. You can't select
some text and wrap it in tags using a batch process; by its very nature
the task is interactive.

The real question is why the original poster is trying to write scripts
to wrap text in HTML tags rather than just using BBEdit's HTML tools,
which already do that and more. You can even assign keyboard shortcuts
to them, so you just hit, say, Ctrl-I and it wraps the selected text in
<i> and </i> tags. No script is needed.

--
Jerry Kindall, Seattle, WA <http://www.jerrykindall.com/>

Send only plain text messages under 32K to the Reply-To address.
This mailbox is filtered aggressively to thwart spam and viruses.
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Jolly Roger

External


Since: Sep 09, 2006
Posts: 1943



(Msg. 12) Posted: Mon May 05, 2008 10:41 pm
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article ,
Jerry Kindall wrote:

> In article , Jolly
> Roger wrote:
>
> > The point is if you have a collection of files and you want to use
> > AppleScript to change some text in them, no text editor is needed. If
> > you do this in pure AppleScript instead, it's quick as lightning. You
> > said you'd try the script I sent you - did you try it? You'll find it's
> > faster than any script that uses a BBEdit window to change text. This is
> > because writing the AppleScript to control the text editor will only
> > slow things down - it takes time for the text editor to draw changes to
> > the window and so on.
>
> I think you've wandered off into the weeds a little. You can't select
> some text and wrap it in tags using a batch process; by its very nature
> the task is interactive.

I'm not the one trying to use a batch process to wrap text in tags. So
it's not *me* who is "off into the weeds", but the original poster. I'm
just showing the OP ways to do what he has stated he wants to do. ; )

> The real question is why the original poster is trying to write scripts
> to wrap text in HTML tags rather than just using BBEdit's HTML tools,
> which already do that and more. You can even assign keyboard shortcuts
> to them, so you just hit, say, Ctrl-I and it wraps the selected text in
> <i> and </i> tags. No script is needed.

Yep. And, as I stated, BBEdit has excellent search and replace
facilities as well.

--
Please send all responses to the relevant news group. E-mail sent to
this address may be devoured by my very hungry SPAM filter. I do not
read posts from Google Groups. Use a real news reader if you want me to
see your posts.

JR
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Fuddled

External


Since: May 04, 2008
Posts: 5



(Msg. 13) Posted: Wed May 07, 2008 6:45 am
Post subject: Re: Applescript to work with text. I'm stuck. [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

In article , Jolly
Roger wrote:

> In article ,
> Jerry Kindall wrote:
>
> > In article , Jolly
> > Roger wrote:
> >
> > > The point is if you have a collection of files and you want to use
> > > AppleScript to change some text in them, no text editor is needed. If
> > > you do this in pure AppleScript instead, it's quick as lightning. You
> > > said you'd try the script I sent you - did you try it? You'll find it's
> > > faster than any script that uses a BBEdit window to change text. This is
> > > because writing the AppleScript to control the text editor will only
> > > slow things down - it takes time for the text editor to draw changes to
> > > the window and so on.
> >
> > I think you've wandered off into the weeds a little. You can't select
> > some text and wrap it in tags using a batch process; by its very nature
> > the task is interactive.
>
> I'm not the one trying to use a batch process to wrap text in tags. So
> it's not *me* who is "off into the weeds", but the original poster. I'm
> just showing the OP ways to do what he has stated he wants to do. ; )
>
> > The real question is why the original poster is trying to write scripts
> > to wrap text in HTML tags rather than just using BBEdit's HTML tools,
> > which already do that and more. You can even assign keyboard shortcuts
> > to them, so you just hit, say, Ctrl-I and it wraps the selected text in
> > <i> and </i> tags. No script is needed.
>
> Yep. And, as I stated, BBEdit has excellent search and replace
> facilities as well.


I'm not sure where the 'batch' comes in. I'm preparing (e.g.) a
paragraph (amongst many others) and I find a string that needs to be in
italics ­ and that was my question: how to quickly pop tags round a
selection. I'm the one who has to do the selection here, there's no
batch about it, so search-and-replace. Each occurence of italics has to
be selected, by human decision.

I simply asked how to write a script that does that. If ­ as Jerry
Kindall says ­ there's a way to do this with BBEdit's "HTML tools" then
I guess I should examine the manual. Or he can drift OT and tell me
here! Though I now have a script that does it; maybe all I've done is
duplicate a BBEdit function?

I'm really appreciative for the help, but Jolly Roger's Convert script
had many more features than I need. I know what file it is I want,
because I'm working in it, and I don't want to save to a new file, just
pop those tags around a selection, manually. That's it.

Anyway ­ thanks to all who responded, and I've now learned more than
I'd expected.
 >> Stay informed about: Applescript to work with text. I'm stuck. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Extracting text from text control in an application from a.. - Hi. I'd like to know if it's possible to extract text from a cocoa text control (or whatever they're called) in an application. Like (and I know that this wouldn't work, but you get the general idea): get value of text control starting with "Line:...

AppleScript Language Guide for AppleScript 2.0 - Hello, The AppleScript Language Guide, updated for AppleScript 2.0, is now available here : <http://developer.apple.com/documentation/AppleScript/ Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html> Patrick -- Patrick Stadelmann..

Applescript RSS - Is there any way to acquire an RSS feed using Applescript? I'd like to be able to specify the RSS URL, then have Applescript consume the most recent 5 entries. Thanks, A

New AppleScript features in 10.5 - On this page <http://www.apple.com/applescript/> (which is formatted in a very un-Apple manner) there's a list of the new features in AppleScript, with each on a clickable link. Some look interesting and I don't want to torpedo any fun discussio...

Leopard, Firefox & Applescript - Can anyone tell me why a script I wrote to log in to my bank no longer works in Firefox since I installed Leopard? Can it by fixed? Thanks
   Macintosh computer (Home) -> Apple Scripts All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]