Tuesday, September 21, 2021

#1 2021-09-10 01:37:05 pm

maximum15
Member
Registered: 2019-02-13
Posts: 2

Keynote -- Determine color of Presenter Notes to color a cell in Excel

Hi there,

I'm trying to write script to determine the color or Paragraph Style of Keynote's Presenter Notes in order to color fill a cell in Excel.

This is just a test script, so it only references one slide. Eventually I'll turn it into a procedural script to do it for the whole deck. I'm not using the entire Presenter Note, only the first paragraph. Each slide's notes will be a specific color and Paragraph Style, so I'm fine with referencing either.

So what I'm trying to do here is determine the color/style of the first paragraph of the presenter notes of slide 3. Then, I'll reference the result to fill a cell in the matching row (equal to slide #) with the same color. For this example, I'm using white, but the final product will cycle through four colors.

When I run the code, I get this error, where "ID #2" is the first paragraph of the presenter note:

error "Can’t get style of \"ID #2\"." number -1728 from style of "ID #2

"

Does anyone here know how to reference the color and/or paragraph style of Keynote's Presenter Notes?

[applescript]tell application "Keynote"
    tell front document
        tell presenter notes of slide 3
            set idQuery to paragraph 1
            if name of paragraph style of idQuery is "ID#" then --Also happy to reference a color here
                set idColor to "{255, 255, 255}"
                tell application "Microsoft Excel"
                    tell active sheet
                        tell column "B"
                            tell row 3
                                tell interior object of cell 2
                                    set color to {255, 255, 255}
                                end tell
                            end tell
                        end tell
                    end tell
                end tell
            end if
        end tell
    end tell
end tell[/AppleScript]

Thanks in advance for any advice you can provide!

Offline

 

#2 2021-09-10 09:27:21 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 105

Re: Keynote -- Determine color of Presenter Notes to color a cell in Excel

Update: Obviously, I was wrong about what you can or can't work with. Dunno why but I was getting errors when I attempted this yesterday.

You can work with the properties of paragraphs (as well as words and characters). These include font, font-size, font-colour. Note that colour in iwork apps (and applescript) is described with 16-bits whereas in excel it's with 8-bits so you'll need to convert, and ideally control the iwork colour if consistency between apps is important. I find that a factor of 257 works well for me (but I haven't tested that for consistency). That said, applescript will actually work (I think) with the first character of whatever object you reference rather than the entire object, as you may have multiple colours within a word or paragraph, so I've set that explicitly.

Applescript:

tell application "Keynote"
   tell front document
       tell presenter notes of slide 3
           set colour_of_crap to color of first character
           --> {3407, 24786, 410}
       end tell
   end tell
end tell

set exCol to {}
repeat with x from 1 to 3
       set end of exCol to (item x of colour_of_crap) / 257 round
end repeat
   --> {13, 96, 2}

tell application "Microsoft Excel"
   tell active sheet
       set color of interior object of range "B3" to exCol
   end tell
end tell

FYI the '[applescript]' tag here is case sensitive. It's easiest to just select the code and click the button.

Last edited by Mockman (2021-09-11 05:08:17 am)


Filed under: excel, keynote

Offline

 

#3 2021-09-10 11:31:51 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2038

Re: Keynote -- Determine color of Presenter Notes to color a cell in Excel

maximum15 wrote:

Hi there,
Does anyone here know how to reference the color and/or paragraph style of Keynote's Presenter Notes?


Hi there. Yes, does.

The following example does not claim to be complete, but answers the last question posed. I recommend running it in the Script Debugger to analyze the structure of presentation notes better.

Also, I want to note that the "style" property does not exist in KeyNote paragraphs, so we create the style ourselves (as in the example) and then set the if condition on it.

Applescript:


tell application "Keynote" to tell front document to tell slide 3
   tell presenter notes
       set PNobject to a reference to it -- a reference to presenter notes object
       tell its paragraph 1 -- a reference to its paragraph 1
           set {R, G, B} to its color
           set theStyle to {its color, its font, its size}
       end tell
   end tell
end tell

-- if theStyle is {{255,255,255},"HelveticaNeue",22} then then
-- tell application "Microsoft Excel" to tell active sheet
-- set color of interior object of range "B3" to {round (R/257), round (G/257), round (B/257)}
-- end tell
-- end if

Last edited by KniazidisR (2021-09-11 01:11:58 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#4 2021-09-13 08:54:41 am

maximum15
Member
Registered: 2019-02-13
Posts: 2

Re: Keynote -- Determine color of Presenter Notes to color a cell in Excel

Thanks, Mockman! That worked perfectly for me. Much appreciated!

KniazidisR, that script didn't quite work for me, but thank you for your help!

Offline

 

#5 2021-09-13 10:38:02 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2038

Re: Keynote -- Determine color of Presenter Notes to color a cell in Excel

maximum15 wrote:

Thanks, Mockman! That worked perfectly for me. Much appreciated!

KniazidisR, that script didn't quite work for me, but thank you for your help!


It is unclear how @Mockman's erroneous code works by paragraph colours, denying their existence. And without containing if condition. And my code, which works for me according to the colours of paragraphs, does not work for you in any way.

The fact that you could not put down the style you need in the if condition does not mean that it does not work. This is to inform other users that your last post will be misleading.

Last edited by KniazidisR (2021-09-13 10:42:39 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#6 2021-09-13 11:40:38 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 105

Re: Keynote -- Determine color of Presenter Notes to color a cell in Excel

maximum15 wrote:

Thanks, Mockman! That worked perfectly for me. Much appreciated!


You're welcome. Glad it works for you.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)