Skip to main content
Inspiring
August 25, 2014
Answered

How to get certain applied styles using script?

  • August 25, 2014
  • 2 replies
  • 1624 views

Hi All,

I need to know how to get certain applied styles using ID Scripting. I don't have much experience in InDesign so need some help.

Here is a screenshot with a sample text with the said styles applied and highlighted.

I need to know what texts in my document have these styles applied like All Caps, Strikethrough, Underline, Subscript and Superscript etc.

Please help.

Thanks!

This topic has been closed for replies.
Correct answer Trevor:

P.s. You probably should be using FindTextPreference


Apply formatting and make selection then run the script

Look through the file for the properties you want.

Pretty easy

2 replies

Jump_Over
Legend
August 25, 2014

Hi,

As you can see - help can come with many faces.

The main question is what kind of help are you asking:

  •     help to understand some syntax
  •     help to code some quick steps
  •     help to create entire script
  •    just create a script

I prefer first three ways and, if so, I need to know

  1. what have you done till now?
  2. and where is a point you want to reach?

I.e. if you say: "...I need to know what texts in my document have these styles applied... "

I am asking: "how you need to know?"

  •      by selecting texts one by one
  •      by alerting one by one
  •      by alerting all at once
  •      by saving it in a file
  •      by sending it to an email...
  •      ... and so on

Script is a set of orders so you have to be as accurate as possible.

Jarek

poortip87Author
Inspiring
August 25, 2014

Yes, I want to know what texts in my document have these styles applied,

I have to create a syntax similar to html and save the output in an xml file.

For eg, for underlined texts for a text frame,

<text-container>

     <text style="underlined">hello</text>

</text-container>

Something like the above.

Trevor:
Legend
August 25, 2014

Hi Poortip87

The first thing you have to understand is how to refer to "where" you want to apply the style.

If you want the script to apply the style to the selected text then you would use for example app.selection[0].strikeThru = true;

If you for example want to underline the last word of the first paragraph of the first story you would use app.activeDocument.stories[0].paragraphs[0].words[-1].underline = true;

If you just wanted the first letter of that word underlined then you would add .characters[0] after the words[-1]

To for example apply All Caps to all the text in all the stories you would use

app.activeDocument.stories.everyItem().texts[0].capitalization = Capitalization.ALL_CAPS;


The easiest way to find how to set properties to a selections is to set them manually and make the selection and then run the script below.

You should be able to find all the properties you want very easily after running the script.

Or you can use Jongwares excellent reference guide. Indesign JavaScript Help

HTH

Trevor




// script to show most of the selection properties by Trevor

// Creative-Scripts.Com (Still not ready!) available (sometimes) for custom scripts $$$

// scripts {at} Creative-Scripts [dot] Com

$.level = 0; // set debug mode to allow try catch (not read only as stated in manual);

if (!app.selection.length) exit();

var c = 0, s = app.selection[0], p,

      a = [], n, er;

for (n in s) {

    try {

        p = s;

        if (p && p.constructor.name === "Enumerator") p = getEnum(p ,n);

        a[c++] = n + ": " + p;

    } catch (er) {a[c++] = n + ": ???"}

}

var f = new File (Folder.temp + +(new Date) + ".txt");

f.open('r');

f.encoding = "UTF-8";

f.lineFeed = ($.os[0]=="M") ? "Macintosh" :" Windows";

f.open('w');

f.write("\uFEFF" + a.join("\r"));

f.close();

$.sleep(300);

f.execute(true);

function getEnum (q, n) {

    var enums = ["AcrobatCompatibility",

    "AddPageOptions",

    "AdornmentOverprint",

    "AlignDistributeBounds",

    "AlignOptions",

    "AlignmentStyleOptions",

    "AlternateGlyphForms",

    "AlternatingFillsTypes",

    "AnchorPoint",

    "AnchorPosition",

    "AnchoredRelativeTo",

    "AnimationEaseOptions",

    "AnimationPlayOperations",

    "AntiAliasType",

    "ArrangeBy",

    "ArrowHead",

    "AssetType",

    "AssignmentExportOptions",

    "AssignmentStatus",

    "AutoEnum",

    "AutoSizingReferenceEnum",

    "AutoSizingTypeEnum",

    "BalanceLinesStyle",

    "BaselineFrameGridRelativeOption",

    "BaselineGridRelativeOption",

    "BehaviorEvents",

    "BevelAndEmbossDirection",

    "BevelAndEmbossStyle",

    "BevelAndEmbossTechnique",

    "BindingOptions",

    "BitmapCompression",

    "BlendMode",

    "BlendingSpace",

    "BookContentStatus",

    "BookletTypeOptions",

    "BoundingBoxLimits",

    "BuildingBlockTypes",

    "BulletCharacterType",

    "BulletListExportOption",

    "Capitalization",

    "ChangeBackgroundColorChoices",

    "ChangeCaseOptions",

    "ChangeConditionsModes",

    "ChangeMarkings",

    "ChangeTextColorChoices",

    "ChangeTypes",

    "ChangebarLocations",

    "ChangecaseMode",

    "ChapterNumberSources",

    "CharacterAlignment",

    "CharacterCountLocation",

    "CharacterDirectionOptions",

    "ClippingPathType",

    "ColorModel",

    "ColorOutputModes",

    "ColorRenderingDictionary",

    "ColorSettingsPolicy",

    "ColorSpace",

    "ComposeUsing",

    "CompressionQuality",

    "ConditionIndicatorMethod",

    "ConditionIndicatorMode",

    "ConditionUnderlineIndicatorAppearance",

    "ContainerType",

    "ContentType",

    "ContourOptionsTypes",

    "ConvertPageBreaks",

    "ConvertShapeOptions",

    "ConvertTablesOptions",

    "CoordinateSpaces",

    "CopyrightStatus",

    "CornerOptions",

    "CreateProxy",

    "CrossReferenceType",

    "CursorTypes",

    "CustomLayoutTypeEnum",

    "DataFormat",

    "DefaultRenderingIntent",

    "DesignOptions",

    "DiacriticPositionOptions",

    "DigitsTypeOptions",

    "DimensionsConstraints",

    "DisplayOrderOptions",

    "DisplaySettingOptions",

    "DistributeOptions",

    "DocumentIntentOptions",

    "DocumentPrintUiOptions",

    "DynamicDocumentsJPEGQualityOptions",

    "DynamicDocumentsTextExportPolicy",

    "DynamicMediaHandlingOptions",

    "DynamicTriggerEvents",

    "EPSColorSpace",

    "EPSImageData",

    "EditingState",

    "EmptyFrameFittingOptions",

    "EndCap",

    "EndJoin",

    "EpubCover",

    "EpubVersion",

    "EventPhases",

    "ExportFormat",

    "ExportLayerOptions",

    "ExportOrder",

    "ExportPresetFormat",

    "ExportRangeOrAllPages",

    "FeatherCornerType",

    "FeatherMode",

    "FeatureSetOptions",

    "FindChangeTransliterateCharacterTypes",

    "FirstBaseline",

    "FitDimension",

    "FitMethodSettings",

    "FitOptions",

    "Fitting",

    "FlattenerLevel",

    "Flip",

    "FlipValues",

    "FloatingWindowPosition",

    "FloatingWindowSize",

    "FollowShapeModeOptions",

    "FontDownloading",

    "FontEmbedding",

    "FontStatus",

    "FontTypes",

    "FootnoteFirstBaseline",

    "FootnoteMarkerPositioning",

    "FootnoteNumberingStyle",

    "FootnotePrefixSuffix",

    "FootnoteRestarting",

    "GIFOptionsPalette",

    "GlobalClashResolutionStrategy",

    "GlobalClashResolutionStrategyForMasterPage",

    "GlowTechnique",

    "GoToZoomOptions",

    "GradientType",

    "GridAlignment",

    "GridViewSettings",

    "GuideTypeOptions",

    "HeaderFooterBreakTypes",

    "HeaderTypes",

    "HorizontalAlignment",

    "HorizontalOrVertical",

    "HyperlinkAppearanceHighlight",

    "HyperlinkAppearanceStyle",

    "HyperlinkAppearanceWidth",

    "HyperlinkDestinationPageSetting",

    "ICCProfiles",

    "IconSizes",

    "ImageAlignmentType",

    "ImageConversion",

    "ImageDataTypes",

    "ImageExportOption",

    "ImageFormat",

    "ImagePageBreakType",

    "ImageResolution",

    "ImageSizeOption",

    "ImportFormat",

    "ImportPlatform",

    "ImportedPageCropOptions",

    "InCopyUIColors",

    "IndexCapitalizationOptions",

    "IndexFormat",

    "InkTypes",

    "InnerGlowSource",

    "InteractiveElementsOptions",

    "InteractivePDFInteractiveElementsOptions",

    "JPEGOptionsFormat",

    "JPEGOptionsQuality",

    "JoinOptions",

    "JpegColorSpaceEnum",

    "Justification",

    "KashidasOptions",

    "KentenAlignment",

    "KentenCharacter",

    "KentenCharacterSet",

    "KinsokuHangTypes",

    "KinsokuSet",

    "KinsokuType",

    "LanguageAndRegion",

    "LayoutRuleOptions",

    "Leading",

    "LeadingModel",

    "LibraryPanelViews",

    "LineAlignment",

    "LineSpacingType",

    "LinkStatus",

    "ListAlignment",

    "ListType",

    "LiveDrawingOptions",

    "Locale",

    "LocationOptions",

    "LockStateValues",

    "MapType",

    "MarkLineWeight",

    "MarkTypes",

    "MatrixContent",

    "MeasurementUnits",

    "MojikumiTableDefaults",

    "MonoBitmapCompression",

    "MoviePlayOperations",

    "MoviePosterTypes",

    "NestedStyleDelimiters",

    "NoteBackgrounds",

    "NoteColorChoices",

    "NothingEnum",

    "NumberedListExportOption",

    "NumberedParagraphsOptions",

    "NumberingStyle",

    "OTFFigureStyle",

    "ObjectTypes",

    "OpenOptions",

    "OpenTypeFeature",

    "OutlineJoin",

    "OverrideType",

    "PDFColorSpace",

    "PDFCompressionType",

    "PDFCrop",

    "PDFJPEGQualityOptions",

    "PDFMarkWeight",

    "PDFProfileSelector",

    "PDFRasterCompressionOptions",

    "PDFXStandards",

    "PNGColorSpaceEnum",

    "PNGExportRangeEnum",

    "PNGQualityEnum",

    "PPDValues",

    "PageBindingOptions",

    "PageColorOptions",

    "PageLayoutOptions",

    "PageNumberPosition",

    "PageNumberStyle",

    "PageNumberingOptions",

    "PageOrientation",

    "PagePositions",

    "PageRange",

    "PageReferenceType",

    "PageSideOptions",

    "PageTransitionDirectionOptions",

    "PageTransitionDurationOptions",

    "PageTransitionOverrideOptions",

    "PageTransitionTypeOptions",

    "PageViewOptions",

    "PaginationOption",

    "PanelLayoutResize",

    "PanningTypes",

    "PaperSize",

    "PaperSizes",

    "ParagraphDirectionOptions",

    "ParagraphJustificationOptions",

    "PathType",

    "PathTypeAlignments",

    "PdfMagnificationOptions",

    "PerformanceMetricOptions",

    "PlacedVectorProfilePolicy",

    "PlayOperations",

    "PointType",

    "Position",

    "PositionalForms",

    "PostScriptLevels",

    "PreflightLayerOptions",

    "PreflightProfileOptions",

    "PreflightRuleFlag",

    "PreflightScopeOptions",

    "PreviewPagesOptions",

    "PreviewSizeOptions",

    "PreviewTypes",

    "PrintLayerOptions",

    "PrintPageOrientation",

    "Printer",

    "PrinterPresetTypes",

    "Profile",

    "ProofingType",

    "RangeSortOrder",

    "RasterCompressionOptions",

    "RasterResolutionOptions",

    "RecordSelection",

    "RecordsPerPage",

    "RenderingIntent",

    "RepaginateOption",

    "ResizeConstraints",

    "ResizeMethods",

    "ResolveStyleClash",

    "RestartPolicy",

    "RotationDirection",

    "RowTypes",

    "RubyAlignments",

    "RubyKentenPosition",

    "RubyOverhang",

    "RubyParentSpacing",

    "RubyTypes",

    "RuleDataType",

    "RuleWidth",

    "RulerOrigin",

    "SWFBackgroundOptions",

    "SWFCurveQualityValue",

    "Sampling",

    "SaveOptions",

    "ScaleModes",

    "Screeening",

    "ScreenModeOptions",

    "ScriptLanguage",

    "SearchModes",

    "SearchStrategies",

    "SelectAll",

    "SelectionOptions",

    "Sequences",

    "ShadowMode",

    "SignatureSizeOptions",

    "SingleWordJustification",

    "SmartMatchOptions",

    "SnapshotBlendingModes",

    "SortAssets",

    "SoundPosterTypes",

    "SourceFieldType",

    "SourceSpaces",

    "SourceType",

    "SpanColumnCountOptions",

    "SpanColumnTypeOptions",

    "SpecialCharacters",

    "SpreadFlattenerLevel",

    "StartParagraph",

    "StateTypes",

    "StaticAlignmentOptions",

    "StoryDirectionOptions",

    "StoryHorizontalOrVertical",

    "StoryTypes",

    "StrokeAlignment",

    "StrokeCornerAdjustment",

    "StrokeFillProxyOptions",

    "StrokeFillTargetOptions",

    "StrokeOrderTypes",

    "StyleConflict",

    "StyleSheetExportOption",

    "SyncConflictResolution",

    "TabStopAlignment",

    "TableDirectionOptions",

    "TableFormattingOptions",

    "TagRaster",

    "TagTextExportCharacterSet",

    "TagTextForm",

    "TagTransparency",

    "TagType",

    "TagVector",

    "TaggedPDFStructureOrderOptions",

    "TaskAlertType",

    "TaskState",

    "TextExportCharacterSet",

    "TextFrameContents",

    "TextImportCharacterSet",

    "TextPathEffects",

    "TextStrokeAlign",

    "TextTypeAlignments",

    "TextWrapModes",

    "TextWrapSideOptions",

    "ThumbsPerPage",

    "TilingTypes",

    "ToolTipOptions",

    "ToolsPanelOptions",

    "TrapEndTypes",

    "TrapImagePlacementTypes",

    "Trapping",

    "UIColors",

    "UITools",

    "UndoModes",

    "UpdateLinkOptions",

    "UserInteractionLevels",

    "VariableNumberingStyles",

    "VariableScopes",

    "VariableTypes",

    "VersionCueSyncStatus",

    "VersionState",

    "VerticalAlignment",

    "VerticalJustification",

    "VerticallyRelativeTo",

    "ViewDisplaySettings",

    "ViewZoomStyle",

    "WarichuAlignment",

    "WatermarkHorizontalPositionEnum",

    "WatermarkVerticalPositionEnum",

    "WhenScalingOptions",

    "XFLRasterizeFormatOptions",

    "XMLElementLocation",

    "XMLElementPosition",

    "XMLExportUntaggedTablesFormat",

    "XMLFileEncoding",

    "XMLImportStyles",

    "XMLTransformFile",

    "ZoomOptions"];

    var l = enums.length,

        s = q.toString(), e, er, a;

    while (l--) {

        try {

            e = $.global [enums];

            if (e.hasOwnProperty (s) && q === e) {

                a = e.reflect.properties;

                a.pop();

                a = (a.length < 2) ? "" : "\r[Possible " + enums+ " Enumerations for " + n + "]:\r" + enums + "." + a.join ("\r" + enums + ".");

                return enums + "." + q.toString () + a;

            }

        }

        catch (er) {};

    }

    return "???." + q.toString ();

}