Applescript with user input for generating Keynote presentation

Hello

I wan’t to create an applescript that takes user input and creates a keynote presentation (and a bit more i have to figure out along the way.)

This is what i got at the moment, but i’m stuck.


set PanelWidth to display dialog "Single panel width in pixel?" default answer ""
set PanelHeight to display dialog "Single panel height in pixel?" default answer ""
set NPanelWidht to display dialog "Number of panels in width?" default answer ""
set NPanelHeight to display dialog "Number of panels in height?" default answer ""

set ScreenResWidth to PanelWidth * NPanelWidht
set ScreenResHeight to PanelHeight * NPanelHeight

display dialog "Single panel width pixel " & (text returned of PanelWidth) & " px" & "
Single panel height " & (text returned of PanelHeight) & " px" & "
Number of LED panels in width " & (text returned of NPanelWidht) & "
Number of LED panels in height " & (text returned of NPanelHeight) & "
LED screen resolution " & (ScreenResWidth) " x " & (ScreenResHeight)


i want the user to first input the width and then the height of a LED panel (eg. 50x50px)
then the total size of the actual LED screen (eg. 20x5 panels)

next it should give a print on screen (dialog) with all inputted data and the total resolution of the LED screen.

next i wan’t the user to input a resolution for the keynote presentation (eg. 1920 x 1080) and after that create a new blank black document in keynote.
next i wan’t to automate the creation of a lot of shapes. (all the LED panels, see photo)
example of a panel that is 50x50px and a screen that is 2 x 5 panels

I just can’t get the first bit of code to work. .

It should look like:

1: Single panel width in pixel? Input: 50
2: Single panel height in pixel? Input: 50
3: Number of panels in width? Input: 2
4: Number of panels in height? Input: 5

Print on screen:
Single panel width pixel 50 px
Single panel height pixel 50 px
Number of LED panels in width 2
Number of LED panels in height 5
LED screen resolution 100 x 250 px

i’m pretty new to Applescript and an old user of C++

Hi. Welcome to MacScripter.

The ‘display dialog’ results are records containing various pieces of information. You need to perform the multiplications on the ‘text returned’ values from those records:


set PanelWidth to text returned of (display dialog "Single panel width in pixel?" default answer "")
set PanelHeight to text returned of (display dialog "Single panel height in pixel?" default answer "")
set NPanelWidht to text returned of (display dialog "Number of panels in width?" default answer "")
set NPanelHeight to text returned of (display dialog "Number of panels in height?" default answer "")

set ScreenResWidth to PanelWidth * NPanelWidht
set ScreenResHeight to PanelHeight * NPanelHeight

display dialog "Single panel width pixel " & PanelWidth & " px" & "
Single panel height " & PanelHeight & " px" & "
Number of LED panels in width " & NPanelWidht & "
Number of LED panels in height " & NPanelHeight & "
LED screen resolution " & (ScreenResWidth) & " x " & (ScreenResHeight) & " px"

Slightly confusingly at first, the two lines in the middle block work even though PanelWidth, NPanelWidht, PanelHeight, and NPanelHeight are actually text representations of numbers rather than the numbers themselves. But AppleScript implicity coerces number values from them for the multiplications.

If you’d like the UI to be a bit more elegant, instead of bombarding users with endless sequential dialogs, take a look at Shane Stanley’s Dialog Toolkit. https://www.macosxautomation.com/applescript/apps/Script_Libs.html#DialogToolkit

thanks a lot! so far so good.

i got the keynote part working perfectly. Now i would like to make a loop function that either.
OK is pressed, runs the keynote execution
Edit again, loops back to beginning for user to input data again.
Exit, exits program.


set Panelwidth to text returned of (display dialog "Single panel width in pixel?" default answer "")
set Panelheight to text returned of (display dialog "Single panel height in pixel?" default answer "")
set ScreenWidthN to text returned of (display dialog "Number of panels in width?" default answer "")
set ScreenheightN to text returned of (display dialog "Number of panels in height?" default answer "")
set DocWidth to text returned of (display dialog "Doc width in pixels?" default answer "")
set Docheight to text returned of (display dialog "Doc height in pixels?" default answer "")
set X to text returned of (display dialog "X start point (0 default)" default answer "")
set Y to text returned of (display dialog "Y start point (0 default)" default answer "")


set ScreenResWidth to Panelwidth * ScreenWidthN
set ScreenResHeight to Panelheight * ScreenheightN


display dialog "Single panel width pixel " & Panelwidth & " px" & "
Single panel height " & Panelheight & " px" & "
Number of LED panels in width " & ScreenWidthN & "
Number of LED panels in height " & ScreenheightN & "
LED screen resolution " & (ScreenResWidth) & " x " & (ScreenResHeight) & " px" & "
Document width " & (DocWidth) & " x " & (Docheight) & " px" & "
Start coordinate for pixelspace " & (X) & " x " & (Y) & " px" buttons {"Edit Again", "Exit", "OK"} default button "OK"



Edit:
The hole thing is now working as intended :D:D

Does anybody know if its possible to make a shape without fill color and just borders in keynote through applescript? And set the borders to 1px wide?


tell the current slide
					set thisShape to ¬
						make new shape with properties ¬
							{position:{X, Y} ¬
								, width:Panelwidth - 1 ¬
								, height:Panelheight - 1 ¬
								, object text:PanelN ¬
								, opacity:100}
				end tell


right now it creates a square that is a solid color. I have to do it manually in keynote after the script has run its course.

No luck, the property background fill type is defined as read only so we can’t set it with standard AppleScript.
You may try to set it with GUI scripting.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 20 octobre 2018 11:53:16

What is the easiest way to find the the “Path” of clicks so i can put it in correct writing?
i mean like this example from another post

tell application "System Events"
click menu item "First Slide" of menu 1 of menu item "Go To" of menu 1 of menu bar item "Slide" of menu bar 1 of process "Keynote"
end tell

how can i see what the different menu items are called?

i know what the it should do, just not what the buttons are called in GUI.

1 step.
Select all / CMD+A / Edit>Select All

  1. go to format tool and select no fill

  2. go to borders and select line, set line to 1px and select color white.

that should be about it.

My first post in this topic:

https://macscripter.net/viewtopic.php?id=46456

mentions four ways to find the path/terms needed for UI scripting.