Giter Club home page Giter Club logo

indesign-automation-python-mac-appscript's Introduction

About

Some example scripts for InDesign automation control on Mac.

About appscript

Keyword conversion

click here

  • Characters a-z, A-Z, 0-9 and underscores (_) are preserved.
  • Spaces, hyphens (-) and forward slashes (/) are replaced with underscores.
  • Ampersands (&) are replaced by the word 'and'.
  • All other characters are converted to 0x00-style hexadecimal representations.
  • Names that match Python keywords or names reserved by appscript have an underscore appended. (※)

※example: class--> class_ , properties--> properties_

Usage

from appscript import *

indd = app("Adobe InDesign CC 2019")
# print(indd.version())
doc = indd.active_document
# print(doc.name())
tfs = doc.text_frames
# print(len(tfs()))
first_tf = tfs[1] # 1-based indexing
characters = first_tf.characters

Add new object

# syntax: parent_object.make(new=k.type)
indd.make(new=k.document) # add a new document
doc.make(new=k.page) # add a new page to doc
doc.pages[1].make(new=k.text_frame) # add a new text frame to page 1
first_tf.make(new=k.table) # add a new talbe to first_tf

Get type/class of an object

doc.class_() # k.document
first_tf.class_() # k.text_frame

Method with keyword

# same to python keyword arguments
doc.close(saving=k.ask, saving_in="path/to/file.indd")

Get value

doc.name()
first_tf.contents()

or

doc.name.get()
first_tf.contents.get()

Set value

first_tf.contents.set("sample contents")
first_tf.fill_color.set("Cyan")
first_tf.geometric_bounds.set([0,0,50,100])

or

# set properties at one time (this is faster)
first_tf.properties_.set({
        k.contents: "sample contents",
        k.fill_color: "Cyan",
        k.geometric_bounds: [0,0,50,100]
    })

Get item

by name

tfs["abc"] # return the 1st text frame whose name is "abc"
# javascript: tfs.itemByName("abc")

by id

tfs.ID(1234) # return text frame whose ID is 1234
# javascript: tfs.itemByID(1234)

by range

characters[1:3] # note: include the 3rd item !!!!!
# javascript: characters.itemByRange(0, 2)

Performance

Running at about 30% speed of javascript/applescript. InDesign document always redraw during script execution. It just runs faster only when we directly execute officially supported language of indesign (javascript/applescript/vbscript) from script panel.

# This doesn't speed up processing
indd.script_preferences.enable_redraw.set(False)

Sample code

indesign-automation-python-mac-appscript's People

Contributors

mlove4u avatar

Watchers

 avatar

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.