Git Product home page Git Product logo

keynotefontchanger's Introduction

This is probably the world's first JavaScript for Automation script written in Literate CoffeeScript. Yes, the very file you are reading is an executable script. To run it, see the instructions at bottom.

Change Keynote Master Font

Helvetica has haunted me again. As you might know in my Yosemite System Font Patcher project, for me the Helvetica font feels too ancient.

Now, I am creating a presentation using Keynote. With its default theme, all slide texts are in Helvetica Neue. And there are 12 master slides to edit.

Yeah, just 12 slides, that's not much, I could have done it manually, but I was too lazy. So I come to my friend, JavaScript for Automation.

The Plan

I opened the Script Editor Dictionary and looked into Keynote. I found out that:

  • The Keynote Application contains documents (that is opening in the app).
  • Each Document contains masterSlides.
  • Each MasterSlide contains textItems.
  • Each TextItem has the objectText property, which is a RichText.
  • The RichText contains the font property, which is the PostScript name of the font.

The Font

For the presentation I'm working on, I think I'll use Avenir Next again. We first need to specify the PostScript name. We can obtain the PostScript name using the Font Book application.

TARGET_FONT = 'AvenirNext-Regular'

The Script

Now, let's get the current document from the Keynote application.

document = Application('Keynote').documents[0]

And for each master slide in it, we will replace the fonts in each text item.

for slide in document.masterSlides
  for textItem in slide.textItems
    textItem.objectText.font = TARGET_FONT

Well, it's that simple.

How to run this script?

First, install CoffeeScript using npm.

npm install -g coffee-script

Then compile this README.litcoffee into JavaScript and pass it to osascript command line tool.

coffee -cp README.litcoffee | osascript -l JavaScript

keynotefontchanger's People

Contributors

dtinth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

keynotefontchanger's Issues

replacing fonts in *all* slides - can't get current font name

This is AWESOME, thank you for posting this. It worked perfectly.

I am working on extending this to replace fonts across all slides (not just Masters). It was an easy change, but now I'd like to make it conditional, i.e. to only replace certain fonts globally, e.g. Arial with Helvetica. My goal is something like:

for textItem in slide.textItems
  if textItem.objectText.font == OLD_FONT
    textItem.objectText.font = NEW_FONT

The problem is, when testing the current RichText's font, the coffeescript console just prints [object ObjectSpecifier], which isn't very helpful. Do you know a way to get / print the font's name? I looked in the AppleScript dictionary for Keynote and didn't see any other properties on font, like "name" or anything.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.