comet.host

The comet.host module provides access to the host environment which is running the priint:comet Python API.

The host environment is either InDesign®, Illustrator® or comet_pdf. Several functions are only available for certain host environments since they set or query host preferences.

Methods

comet.host.getType()

Returns the host application the script environment is running in

Returns:

The host environment.

One of Host environments

Return type:

int

Available:

InDesign® comet_pdf® Illustrator®

CScript:

system::version

Examples:

Determine the host application and log it.

#!py
#pragma plain

import comet

def main():
    host = comet.host.getType()
    message = ''

    if host == comet.constants.kHostInDesign:
        message = 'Running in InDesign'
    elif host == comet.constants.kHostInDesignServer:
        message = 'Running in InDesign Server'
    elif host == comet.constants.kHostCometPDF:
        message = 'Running in comet_pdf'
    elif host == comet.constants.kHostIllustrator:
        message = 'Running in Illustrator'

    comet.wlog(message)

    return 0
comet.host.getVersion()

Returns the major version for the active host software.

Here is an example of possible return values:

  • 17 : InDesign® 2022

  • 18 : InDesign® 2023

  • 19 : InDesign® 2024

  • 20 : InDesign® 2025

  • 26 : Illustrator® 2022

  • 27 : Illustrator® 2023

  • 28 : Illustrator® 2024

  • 29 : Illustrator® 2025

Returns:

The host version

Return type:

int

Available:

InDesign® Illustrator®

CScript:

system::version

Examples:

Get the version number of the host application, calculate the year number and log it.

#!py
#pragma plain

import comet

def main():
    version = comet.host.getVersion()
    host = comet.host.getType()

    #Illustrator and InDesign have different offsets between their version number and their year number.
    if host == comet.constants.kHostInDesign or host == comet.constants.kHostInDesignServer:
        comet.wlog(f'We are running InDesign {"Server" if host == comet.constants.kHostInDesignServer else ""}® {version + 2005}')
    elif host == comet.constants.kHostIllustrator:
        comet.wlog(f'We are running Illustrator® {version + 1996}')

    return 0
comet.host.getIsServer()

Returns whether the active host is a server (Only true for InDesign® Server)

Returns:

Whether the host is a server

Return type:

bool

Available:

InDesign®

CScript:

system::is_server

comet.host.getLanguage()

Get the active language the host software is running in.

The following keys can be returned:

  • 0 : English (US)

  • 1 : English (UK)

  • 2 : German

  • 3 : French

  • 4 : Japanese

  • 5 : Spanish

  • 6 : Portgese

  • 7 : Swedish

  • 8 . Danish

  • 9 : Dutch

  • 10 : Italian

  • 11 : Norwegian

  • 12 : Finnish

  • 13 : Greek

  • 14 : Czeck

  • 15 : Polish

  • 16 : Croatian

  • 17 : Hungarian

  • 18 : Russian

  • 19 : Slowakian

  • 20 : Turkish

  • 21 : Romanian

  • 22 : Bulgarian

  • 23 : Belorussia

  • 24 : Estonian

  • 25 : Latvian

  • 25 : Lithuanian

  • 27 : Slovenian

  • 28 : Ukrainian

  • 29 : Hebrew

  • 30 : Arabic

  • 31 : Korean

  • 32 : Chinese

  • 33 : Chinese (Taiwan)

  • 34 : Tamil

  • 35 : Thai

  • 36 : Vietnamese

  • 37 : Albanian

Returns:

The language key

Return type:

int

Available:

InDesign® comet_pdf® Illustrator®

CScript:

system::language

Examples:

Greet the user in their local language.

#!py
#pragma plain

import comet

def main():
    language = comet.host.getLanguage()
    message = ''
    if language == 0 or language == 1:
        #English
        message = 'Hello world'
    elif language == 2:
        #German
        message = 'Hallo welt'
    elif language == 3:
        #French
        message = 'Bonjour le monde'
    elif language == 4:
        #Japanese
        message = 'ハロー・ワールド'

    comet.dialog.showMessage(message)

    return 0
comet.host.getApplicationPath()

Determine the path to the host application.

This is the folder to where the host executable is in, e.g. C:/Program Files/Adobe/Adobe InDesign 2021

Returns:

The folder of the host application

Return type:

str

Available:

InDesign® comet_pdf® Illustrator®

CScript:

system::app_path

comet.host.getPluginPath()

Determine the path to the Plugin subfolder of the host application.

This is the folder where the comet plugin subfolder is in, e.g. C:/Program Files/Adobe/Adobe InDesign 2021/Plug-Ins

Returns:

The folder to the plugins

Return type:

str

Available:

InDesign® comet_pdf® Illustrator®

CScript:

system::plugin_path

comet.host.getSelection()

Provides a description of the current selection.

Returns:

A tuple containing the following information:

  • int: Start of the text selection. If the text selection cannot be determined, the return value is constants.kEnd.

  • int: Length of the text selection. If the text selection cannot be determined, the return value is 0.

  • CFrame: Frame of the text selection. If no text selection is set, the value is None.

  • list [CPageItem] | None: List of selected frames. If a text selection is set, the first (and only) element of this list is the text frame containing the cursor.

  • CTable | None: Table containing the text selection. If no table text is selected, the value is None.

  • tuple containing the following information:
    • int: Column number (0-based) of a table text selection. If no table text is selected, the value is -1.

    • int: Row number (0-based) of a table text selection. If no table text is selected, the value is -1.

    • int: First unselected column of a table (or -1 if no table cells/no table text is selected).

    • int: First unselected row of a table (or -1 if no table cells/no table text is selected).

Return type:

tuple[int, int, CPageItem | None, list[CPageItem], CTable | None, tuple[int, int ,int, int]]

Available:

InDesign®

CScript:

textmodel::selection

Examples:

Get the selection information and log it depending on the selection context.

#!py
#pragma plain

import comet

def main():
    host = comet.host.getType()

    #In server applications we have no selection.
    if host == comet.constants.kHostInDesignServer or host == comet.constants.kHostCometPDF:
        return 0

    selectionData = comet.host.getSelection()

    #Check if we have a text selection.
    textStart, textLength, textFrame, *rest = selectionData

    if textFrame and textStart >= 0:
        #We have a text selection
        comet.wlog(
            f'Text selection:'
            f'\n\tStart: {textStart}'
            f'\n\tLength: {textLength}'
            f'\n\tFrame: {textFrame}'
        )

        #When a text selection is active, the selection may be in a table.
        #Start after the list of selected frames which we don't need here.
        table, coords = selectionData[4:]

        if table and coords:
            column, row, columnEnd, rowEnd = coords

            comet.wlog(
                f'\tTable: {table}'
                f'\n\tColumn: {column}'
                f'\n\tRow: {row}'
                f'\n\tColumnEnd: {columnEnd}'
                f'\n\tRowEnd: {rowEnd}'
            )

        return 0

    #Check if we have a frame selection
    frames = selectionData[3]
    if frames:
        #We have a frame selection
        comet.wlog('Frame selection:')
        for frame in frames:
            comet.wlog(f'\t{str(frame)}')

        return 0

    return 0
comet.host.getSessionArgument(option)

Determine the value of an program option or an value of the environment configuration.

The call only returns meaningful values in InDesign® Server.

Parameters:

option (str) –

Valid program option or environment configuration key.

The return type of this function changes depending on the provided key.

The following keys and their return types are supported:

InDesign® Server program options
  • ’-adminport’ | int

  • ’-configuration’ | str

  • ’-console’ | bool

  • ’-noconsole’ | bool

  • ’-errorlist’ | bool

  • ’-noerrorlist’ | bool

  • ’-heartbeatupdateinterval’ | int

  • ’-home’ | str

  • ’-host’ | str

  • ’-iorfile’ | str

  • ’-LogToApplicationEventLog’ | bool

  • ’-maxerrors’ | int

  • ’-maxwaitss’ | int

  • ’-noblockss’ | bool

  • ’-onmainthread’ | bool

  • ’-pluginpath’ | str

  • ’-port’ | int

  • ’-previews’ | bool

  • ’-nopreviews’ | bool

  • ’-rxidletimeout’ | int

  • ’-seh’ | bool

  • ’-sendcrashlogs’ | bool

  • ’-nosendcrashlogs’ | bool

priint:comet option extensions for InDesign® Server
  • ’-cometconfig’ | str

  • ’-cometlog’ | str

  • ’-cometlic’ | str

  • ’-cometcache’ | str

  • ’-cometapilog’ | str

  • ’-cometport’ | int

  • ’-cometaccepttimeout’ | int

  • ’-cometreceivetimeout’ | int

  • ’-cometsendtimeout’ | int

  • ’-cometyield’ | int

  • ’-cometlogrotate’ | int

  • ’-cometthreshold’ | int

  • ’-cometprogress’ | bool

  • ’-cometdrawidle’ | bool

  • ’-cometparanoidredraw’ | bool

  • ’-cometidmlcache’ | bool

  • ’-cometxmlparser’ | int

  • ’-playback’ | int

  • ’-playbackpath’ | str

  • ’-soaplog’ | int

  • ’-debugpy’ | int

Environment settings by app.comet.setEnvironment
  • ’endpoint’ | str

  • ’getEnvironment’ | str

  • ’isConnected’ | bool

  • ’isPubserverConnection’ | bool

  • ’scriptIO’ | str

  • ’upTime’ | int

Raises:

TypeError – When parameter types are invalid

Returns:

The value of the requested session/environment configuration.

Return type:

bool | int | str

Available:

InDesign®

CScript:

server::get_session_arg

comet.host.getPDFProfileNames(source='')

Get a list of all available PDF profiles.

Parameters:

source (str) –

  • Empty str: Get the profiles from the host preferences

  • Else: Path to an XML file containing exported PDF profiles

Returns:

The PDF profile names

Return type:

list[str]

Raises:
Available:

InDesign®

CScript:

prefs::list_pdfstyles

Examples:

Write a list of host application PDF profiles to a file on the desktop.

#!py
#pragma plain

import comet

def main():
    profileNames = comet.host.getPDFProfileNames()

    with open(comet.uncurtain('$DESKTOP/profiles.txt'), 'w', encoding = 'utf8') as outFile:
        for profile in profileNames:
            outFile.write(f'{profile}\n')

    return 0
comet.host.exportPDFProfiles(destination, filter=[])

Export available PDF profiles to an XML file.

Parameters:
  • destination (str) –

    Full path to the output file.

    Will be overwritten if it exists

  • filter (list[str]) –

    List of profiles to include.

    • Empty list: Export all profiles

Return type:

None

Raises:
Available:

InDesign®

CScript:

prefs::export_pdfstyles

Examples:

Export PDF profiles to an XML file on the desktop.

comet.host.exportPDFProfiles(comet.uncurtain('$DESKTOP/profiles.xml'))
comet.host.importPDFProfiles(source, mode=0, filter=[])

Import PDF profiles from an XML file.

Parameters:
  • source (str) – Full path to an input file written by exportPDFProfiles()

  • mode (int) –

    Behavior when an imported profile already exists

    • 0: Overwrite

    • 1: Skip

    • 2: Abort

  • filter (list[str]) –

    List of profiles to include during import.

    • Empty list: Import all profiles

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError

    • When parameter str is empty

    • When parameter mode has invalid value

  • CometError – On internal error

Available:

InDesign®

CScript:

prefs::import_pdfstyles

Examples:

Import PDF profiles from an XML file on the desktop.

comet.host.importPDFProfiles(comet.uncurtain('$DESKTOP/profiles.xml'))
comet.host.getPrintProfileNames(source='')

Get a list of all available print profiles.

Parameters:

source (str) –

  • Empty str: Get the profiles from the host preferences

  • Else: Path to an XML file containing exported print profiles

Returns:

The print profile names

Return type:

list[str]

Raises:
Available:

InDesign®

CScript:

prefs::list_printstyles

comet.host.exportPrintProfiles(destination, filter=[])

Export available print profiles to an XML file.

Parameters:
  • destination (str) –

    Full path to the output file.

    Will be overwritten if it exists

  • filter (list[str]) –

    List of profiles to include.

    • Empty list: Export all profiles

Return type:

None

Raises:
Available:

InDesign®

CScript:

prefs::export_printstyles

comet.host.importPrintProfiles(source, mode=0, filter=[])

Import print profiles from an XML file.

Parameters:
  • source (str) – Full path to an input file written by exportPrintProfiles()

  • mode (int) –

    Behavior when an imported profile already exists

    • 0: Overwrite

    • 1: Skip

    • 2: Abort

  • filter (list[str]) –

    List of profiles to include during import.

    • Empty list: Import all profiles

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError

    • When parameter str is empty

    • When parameter mode has invalid value

  • CometError – On internal error

Available:

InDesign®

CScript:

prefs::import_printstyles

comet.host.getFlattenerProfileNames(source='')

Get a list of all available transparency flattener profiles.

Parameters:

source (str) –

  • Empty str: Get the profiles from the host preferences

  • Else: Path to an XML file containing exported flattener profiles

Returns:

The flattener profile names

Return type:

list[str]

Raises:
Available:

InDesign®

CScript:

prefs::list_flattenerstyles

comet.host.exportFlattenerProfiles(destination, filter=[])

Export available transparency flattener profiles to an XML file.

Parameters:
  • destination (str) –

    Full path to the output file.

    Will be overwritten if it exists

  • filter (list[str]) –

    List of profiles to include.

    • Empty list: Export all profiles

Return type:

None

Raises:
Available:

InDesign®

CScript:

prefs::export_flattenerstyles

comet.host.importFlattenerProfiles(source, mode=0, filter=[])

Import flattener profiles from an XML file.

Parameters:
  • source (str) – Full path to an input file written by exportFlattenerProfiles()

  • mode (int) –

    Behavior when an imported profile already exists

    • 0: Overwrite

    • 1: Skip

    • 2: Abort

  • filter (list[str]) –

    List of profiles to include during import.

    • Empty list: Import all profiles

Return type:

None

Raises:
  • TypeError – When parameter types are invalid

  • ValueError

    • When parameter str is empty

    • When parameter mode has invalid value

  • CometError – On internal error

Available:

InDesign®

CScript:

prefs::import_flattenerstyles