Benches macOS

7

How to get currently selected text in pow…

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

Could some kind soul please explain to me how I can get the currently selected text in an applescript with powerpoint 2008 (version 12.1.5).

I'm assuming that the user has actually selected some text and, of course, powerpoint shows the normal view.

It must be possible (according to
http://www.officeformac.com/blog/filter/[email protected]@ ) , but I can't find any examples anywhere. (And I am an applescript newbie.)

(I want to change some attributes of that selected text.)

All kinds of hints, pointers, examples, suggestions will be highly appreciated.

Thanks a lot in advance.

Best regards,

Gabriel.

Message was edited by: GabrielZ

7 replies

Sign in or join Beachball Help to reply.

  1. 0

    GabrielZ

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Can no one at least give me a hint? pleeeeease ....

    Regards,

    Gabriel.

  2. 0

    ericmeyers

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I can give you a hint, but I don't have PowerPoint 2008 to try any of this.

    http://www.microsoft.com/mac/developers/default.mspx?CTT=PageView&clr=99-24-0&ta rget=0df3c7c7-0ace-48b2-9efc-68e645738b201033&srcid=9fe7f4d1-5fca-4d45-aa51-6384 8186ee321033&ep=7

    Eric

  3. 0

    GabrielZ

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks a lot for the hint ... could you pleeease also give me a hint, how a "sentence" in applescript containing that selection object might look like?

    For instance, I have no clue how to obtain the currently active shape (i suppose that object is what i need in order to get hold of the selected text ...)

    As I said, I'm a newbie regarding applescript 😉

    Thanks a lot in advance.

    Best regards,

    Gabriel.

    Message was edited by: GabrielZ

  4. 0

    GabrielZ

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I experimented a little and now I seem to be stuck at the following point:

    tell application "Microsoft PowerPoint"      activate -- bring it to the front      --launch -- just launch it, if it is not yet running, but it stays in the background            set theSelection to selection of active window      set theSelType to selection type of theSelection      display dialog (theSelType as string)            if theSelType is text then             -- should be ' .. is selection type text' ?           display dialog "text"      end if end tell

    Now, when I select some text and run the script, I get the text "selection type text" in the dialog box.

    And when I select a text box, for instance, and run the script, then I get the output "selection type shapes".

    Fine.

    However, I don't know what to write in the line 'if theSelType is
    enum then'!

    If I write 'selection type text' in place of
    enum, then the script editor won't save it.

    If I write 'text' (as shown in the code above), then it does save it, but the body of the if is never executed.

    Clueless ...

    Best regards,

    Gabriel.

  5. 0

    ericmeyers

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Honestly without having PP 2008 myself I'd be guessing. Hopefully someone else can chime in.

    Eric

  6. 0

    Hiroto

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Hello Gabriel,

    Perhaps something like the code below may return the text in selection.

    Wild guess based on the dictionary. Not tested.

    --CODE1

    tell application "Microsoft PowerPoint" -- PPT 2008

    tell active window

    set t to content of text range of selection

    end tell

    end tell

    return t

    --END OF CODE1

    As for the said constant name (enumeration), run the following code and check the result window.

    Whatever returned there should be the constant to be used in your script.

    --CODE2

    tell application "Microsoft PowerPoint" -- PPT 2008

    tell active window

    return get selection type of selection

    end tell

    end tell

    --END OF CODE2

    Good luck,

    H

  7. 0

    GabrielZ

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Thanks a lot for your response.

    Thanks to your response, I tried it again, and today it's working!

    (I could've sworn that yesterday I tried it exactly the same way! ...)

    Anyway, for the record, here is the complete script:

    (is there any proper way to format code here? perhaps by a tag?)

    -------- code

    tell application "Microsoft PowerPoint"

    activate -- bring it to the front

    set theSelection to selection of active window

    set theSelType to selection type of theSelection

    if theSelType is selection type text then

    -- only change font attribute if user has selected text;

    -- not, if he has selected something else (shape, slide, etc.)

    set theTextRange to text range of theSelection

    -- display dialog (get font name of font of theTextRange)

    -- display dialog ( (content of theTextRange) as string)

    tell font of theTextRange

    set fontSize to get font size

    if fontSize ≥ 18 then

    set fontSize to fontSize + 4

    else

    set fontSize to fontSize + 2

    end if

    set {font size, subscript, base line offset} to ¬

    {fontSize, true, -0.15}

    end tell

    else

    if theSelType is selection type none then set seltype to "none"

    if theSelType is selection type slides then set seltype to "slides"

    if theSelType is selection type shapes then set seltype to "shapes"

    display dialog "No text selected (you selected " & seltype & ")" buttons {"Oh well .."} default button 1

    end if

    end tell

    -------- code

    This code works with powerpoint 2008, version 12.1.5.

    Best regards,

    Gabriel.