Tuesday, September 29, 2020
  • Index
  •  » Code Exchange
  •  » AppleScript to ask for values and set values in application Keynote.

#1 2020-08-05 12:36:28 pm

Fredrik71
Member
Registered: 2019-10-23
Posts: 399

AppleScript to ask for values and set values in application Keynote.

AppleScript to ask for values and set values in application Keynote.
This are included in this script... Document, Current Slide, Shape and Text Item.

I have try to do it as clear as possible. I have set variable name of theDocument to front document
and use tell block from my document to ask for other objects. For me its a way to
make the code more clean and understand the structor of AppleScript and where all
properties belong.


Applescript:

tell application "Keynote"
   set theDocument to front document
   
   --- DOCUMENT
   
   -- Get the name of the Keynote document.
   tell theDocument to set itsName to name
   log "Document name: " & itsName
   
   -- Get the slides count.
   tell theDocument to set itsCountSlides to its (count slides)
   log "Amount of slides: " & itsCountSlides
   
   -- Get the name of current Theme.
   tell theDocument to set itsTheme to its name of document theme
   log "Document theme: " & itsTheme
   
   -- Get the slide Size.
   tell theDocument to set {itsWidth, itsHeight} to its {width, height}
   log "Slide size: " & {itsWidth, itsHeight}
   
   -- Get the maximum idle duration.
   tell theDocument to set itsMaximumIdleDuration to its maximum idle duration
   log "Maximum idle duration: " & itsMaximumIdleDuration
   
   -- Get the slide numbers showing.
   tell theDocument to set itsSlideNumbersShowing to its slide numbers showing
   log "Slide numbers showing: " & itsSlideNumbersShowing
   
   --- CURRENT SLIDE
   
   -- Get the slide number of current slide.
   tell theDocument to tell current slide to set itsSlideNumber to slide number
   log "Current slide number: " & itsSlideNumber
   
   -- Get the base slide master slide name of current slide.
   tell theDocument to tell current slide to set itsBaseSlideMasterSlide to its name of base slide
   log "Base slide master slide: " & itsBaseSlideMasterSlide
   
   -- Get the default title item of current slide.
   tell theDocument to tell current slide to set itsDefaultTitleItem to its object text of default title item
   log "Default title item: " & itsDefaultTitleItem
   
   -- Get the default body item of current slide.
   tell theDocument to tell current slide to set itsDefaultBodyItem to its object text of default body item
   log "Default body item: " & itsDefaultBodyItem
   
   -- Get the value of title showing of current slide.
   tell theDocument to tell current slide to set itsTitleShowing to its title showing
   log "Title showing: " & itsTitleShowing
   
   -- Get the value of body showing of current slide.
   tell theDocument to tell current slide to set itsBodyShowing to its body showing
   log "Body showing: " & itsBodyShowing
   
   -- Get the value of skipped of current slide.
   tell theDocument to tell current slide to set itsSkipped to its skipped
   log "Skipped: " & itsSkipped
   
   -- Get the presenter notes of current slide.
   tell theDocument to tell current slide to set itsPresenterNotes to its presenter notes
   log "Presenter notes: " & itsPresenterNotes
   
   tell theDocument to tell current slide to set itsTransitionProperties to its transition properties
   log "Transition properties"
   log {itsTransitionProperties}
   
   
   --- SHAPE
   
   tell theDocument to tell current slide to tell shape 1
       -- SET VALUE
       set opacity to 100 --> integer (0 - 100)
       -- GET VALUE
       set itsOpacity to opacity
       log itsOpacity
       
       -- GET VALUE
       set itsParent to parent
       log itsParent
       
       -- SET VALUE
       set reflection showing to true --> (boolean)
       -- GET VALUE
       set itsReflectionShowing to reflection showing
       log itsReflectionShowing
       
       -- NOTE: TO SET VALUE OF BACKGROUND_FILL_TYPE USE GUI SCRIPTING
       set itsBackgroundFillType to background fill type
       log itsBackgroundFillType
       
       -- SET VALUE
       set {width, height} to {400, 400}
       -- GET VALUE
       set {itsWidth, itsHeight} to {width, height}
       log {itsWidth, itsHeight}
       
       (**
       * SET VALUE
       * To get centre position of shape
       * (1 - (width/2)) + position), (1 - (height/2)) + position)
       * If the screen size is 1920x1080...
       *)

       set {itsOffsetX, itsOffsetY} to {100, 0}
       set position to {(1 - (itsWidth / 2)) + (1920 / 2) - itsOffsetX, (1 - (itsHeight / 2)) + (1080 / 2) - itsOffsetY}
       -- GET VALUE
       set itsPosition to position
       log itsPosition
       
       -- SET VALUE
       set object text to "B"
       -- GET VALUE
       set itsObjectText to object text
       log itsObjectText
       
       
       -- SET VALUE
       set rotation to 45
       -- GET VALUE
       set itsRotation to rotation
       log itsRotation
       
       -- SET VALUE
       set reflection value to 25
       -- GET VALUE
       set itsReflectionValue to reflection value
       log itsReflectionValue
       
       -- SET VALUE
       set locked to false
       -- GET VALUE
       set itsLocked to locked
       log itsLocked
   end tell
   
   --- TEXT ITEM
   
   tell theDocument to tell current slide to tell text item 1
       -- SET VALUE
       set opacity to 75
       -- GET VALUE
       set itsOpacity to opacity
       log itsOpacity
       
       -- GET VALUE
       set itsParent to parent
       log itsParent
       
       -- SET VALUE
       set reflection showing to true --> (boolean)
       -- GET VALUE
       set itsReflectionShowing to reflection showing
       log itsReflectionShowing
       
       -- NOTE: TO SET VALUE OF BACKGROUND_FILL_TYPE USE GUI SCRIPTING
       set itsBackgroundFillType to background fill type
       log itsBackgroundFillType
       
       -- SET VALUE
       set {width, height} to {1000, 100}
       -- GET VALUE
       set {itsWidth, itsHeight} to {width, height}
       log {itsWidth, itsHeight}
       
       set {itsOffsetX, itsOffsetY} to {0, 400}
       set position to {(1 - (itsWidth / 2)) + (1920 / 2) - itsOffsetX, (1 - (itsHeight / 2)) + (1080 / 2) - itsOffsetY}
       -- GET VALUE
       set itsPosition to position
       log itsPosition
       
       -- SET VALUE
       set rotation to 0
       -- GET VALUE
       set itsRotation to rotation
       log itsRotation
       
       -- SET VALUE
       set object text to "Square in 45 degrees with B inside"
       -- GET VALUE
       set itsObjectText to object text
       log itsObjectText
       
       -- SET VALUE
       set reflection value to 25
       -- GET VALUE
       set itsReflectionValue to reflection value
       log itsReflectionValue
       
       -- SET VALUE
       set locked to false
       -- GET VALUE
       set itsLocked to locked
       log itsLocked
   end tell
end tell


I could teach you to cook but I couldn't do anything if you do not have desire or commitment for it.

Online

 
  • Index
  •  » Code Exchange
  •  » AppleScript to ask for values and set values in application Keynote.

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)