Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > AppleScript - Get the Selection... in TextEdit???

AppleScript - Get the Selection... in TextEdit???
Thread Tools
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Aug 7, 2003, 11:46 AM
 
Hi,

I am trying to write a simple AppleScript that I can put in my Script Menu.

What I intend the script to do is this:

*get the selected text in the foremost application.
*replace that text with HTML-style tags around it.

So far I am having problems getting the current selection.

the following script has different results depending on the app:

Code:
tell application someApp get the selection end tell
when someApp == Script Editor
it returns:

Code:
characters 57 thru 64 of document 1
but when someApp == textEdit it returns:

Code:
"TextEdit got an error: NSCannotCreateScriptCommandError"
In fact I can't see any way of getting the selected text the document at all.

Is it possible (without resorting to UIScripting?)
     
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Aug 8, 2003, 02:58 AM
 
You're out of luck as far as TextEdit.app is concerned - it doesn't support the 'selection' object.

Some people have blamed limitations in Cocoa's libraries, but some Cocoa apps do support selection so I don't believe that one.

Do you need to use TextEdit at all? Can you use direct calls within AppleScript to read the file?
Gods don't kill people - people with Gods kill people.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Aug 8, 2003, 05:40 AM
 
Originally posted by Camelot:
You're out of luck as far as TextEdit.app is concerned - it doesn't support the 'selection' object.

Some people have blamed limitations in Cocoa's libraries, but some Cocoa apps do support selection so I don't believe that one.

Do you need to use TextEdit at all? Can you use direct calls within AppleScript to read the file?
Thanks for the confirmation.

- Direct calls to read the file wouldn't tell me which part was selected.

I have decided to implement this as a service instead.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:17 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2