Scripting Commands in GEDitCOM II

Many commands are available that let you interrogate documents or records for information or do miscellaneous calculations and other actions. Most commands are available when using Internal Scripts, AppleScript, Python scripts. Some special any new commands are defined for Internal Scripting only.

Scripting Commands

All of GEDitCOM II's scripting commands, in alphabetical order, are listed below. Click each command for details. Also see general command about all commands below the table.

addAlbum addList addObject addRecord addString
addStructure Beep begin undo bulk reader can link
clearContextInfo close close child Compress consolidate multimedia
copyFile CreateDictionary CreateDocument CreateList CreateScriptOutput
css date format date numbers date parts date style
date text date today date year delete DeleteFiles
description detach difference display dropOn
end undo evaluateExpression export gedcom find structures format name
get GetObject intersection insertObject insertString
head list ancestors list descendants join local string
LonLatBounds makeFolder merge with move moveto
name parts newline notify progress offset openFile
openURL out pop populate PreChecks
print putPasteboard ReadPasteboard refresh formats refresh scripts
remove removeValueForKey replace RevealInFinder run script
safe html SafeTex save sdn range set
setNumberForKey setObjectForKey setStringForKey show ancestors show browser
show browserpane show descendants sleep sort sort data
soundex sublist SubProcess union uniqueFile
user choice user input user openFile user openfolder user option
user saveFile user select valueForKey write  

Documentation for each command lists which objects support that command. Required arguments are listed with the command; optional arguments are enclosed in square brackets. Commands that work in AppleScript are defined by the AppleScript useage style. Each of these commands is followed by the format needed to use them in Internal Scripts or Python scripts. When using Internal scripts, optional arguments (in square brackets) can be omitted only if all prior arguments are provided. When using Python, all arguments must be supplied, but you can usually specify None (in Python) for optional arguments that are not needed.

Some commands only became available in certain versions of GEDitCOM II or GEDitCOM; this condition is indicated with "(since x.y/a.b)" where "x.y" is the GEDitCOM II version needed and "a.b" is the GEDitCOM version needed. Any command or feature not labeled should available in any version, although Internal Scripts always require 3.0/1.0.

Note that numerous commands are designated as "Internal Script use only." Although such commands are not available to AppleScript or Python scripts, most of those commands can be accomplished in those languages by other methods (e.g., working with lists or dictionaries).

Using Commands in Internal Scripts

Commands in internal scripts have one of two formats:

command (arg1),(arg2),[(arg3)],...
(object).command (arg1),(arg2),[(arg3)],...

The first is a "direct" commmand that is used without reference to any object. The second is a command specific to an object. The object targeted by the command is determined by the object specifier in (object). Two common methods to target and object are to use just an object name or a variable that contains just an object name:

indi.listAncestors alist,5
#ref="indi"
^#ref.listAncestors atlist,5

Here indi is object name for an individual record. The first method uses the object's name. The second uses caret '^' in front of variable that contains the object name. These are common methods to target objects but the object specifier can use multiple (atom)'s too. Whenever the object specifier uses a variable in the (root) element, however, it must be prefaced with a caret '^' symbol.

All command arguments (e.g., (arg1), (arg2), ...) are evaluated first as an expression and the expression result is passed to the command. Some consequences of this process are:

  1. Some internal scripting commands need objects for one or more of their command arguments (indicated indicated in documentation by "(object1)", "(object2)", etc.). Objects for command arguments are passed using a quoted object specifier, although quotes can be omitted if passing just an object's name (or an expression that evaluates to an object's name or an object specifier).
  2. Some commands set a variable and/or any object name:

Important: Targeting a command with an invalid object (i.e., (object).(command) where (object) is a failed object specifier>) or passing an invalid object to a command that expects an object will normally cause an error that ends the script. Such errors can be trapped by testing the object first using:

  1. Object assignment using @objName = "(object)"
  2. The GetObject objName,"(object)" command

If (object) in either option is a failed specifier, these options will set objName to a None object. These commands can therefore validate any object before targeting it with other commands or using it an "@" expressions to read an object property. For example, if you are accessing albums by name, but not sure that the album exists, you can use following code to avoid aborting the script with an invalid object reference:

#name="My Album"
@album = "gcapp.documents.0.albums.#name"
ifDef album
  ! album found and can use it
else
  ! album not found, decide what to do
endif

Command Documentions

(object).addAlbum objName,[(name)]
Add a new album to the document with optional name (it will be called "New Album" if name is not provided).
    Supported By: documents
    Internal Script use only
(object).addList "(object1)"[,"(object2)",...]
Adds individual elements of one or more lists or GC lists to the target object. A error results if any (object#) is an invalid object specifier. Use addObject to add a list as a single object to another list.
    Supported By: lists
    Internal Script use only
(object).addObject "(object1)"[,"(object2)",...]
Adds one or more objects to the target object. An error results if any argument is an invalid object specifier. Objects that are lists or GC lists are added as list objects (i.e., a list can contain other lists). Use addList to add elements of those lists to the target list instead.
    Supported By: lists
    Internal Script use only
(object).addRecord objName,(type),[(info)]
(object).addRecord "(object1)"[,"(object2)",...]
The first form is when the target (object) is a document. This command then adds a new record of type (type) to the document and sets objName to the new record's object. (type) is GEDCOM record type code such as INDI, FAM, SOUR, NOTE, etc. When adding INDI records, (info) can be "male" or "female" to set sex of the individual. When adding _PLC records (custom place records), (info) can be a place name and and it should be unique in the file (if not, a number will be added to make it unique. If (type) is not a standard GEDCOM record type or one of the custom GEDitCOM II record types, the new record will be added as a custom record type.
    The second form is when the target (object) is an album. This command then adds one or more GEDCOM records defined by (object#) to the album. If any (object#) is a list or GC list, the GEDCOM records in those lists are added to the album. Any objects in a list that are not GEDCOM records are skipped. No errors are caused by trying to add non-records or using a list that has no GEDCOM records. A script can check if the command added any records by checking the album count property before and after the command.
    Supported By: documents (first form), albums (second form)
    Internal Script use only
(object).addString (expr1),[(expr2),...]
Adds one or more strings to the target object. All arguments must be valid expressions.
    Supported By: lists
    Internal Script use only
Beep
Sound standard alert beep.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2/1.0)
(object).addStructure (struct),(tag),(contents),[(index) or (after)]
Create a new GEDCOM structure, set object (struct) to the new structure, and then add it to the target object. The structure's tag and contents are required. The level is automatically set to one higher than the target object. The new structure is added at the optional (index) in subordinate structures or after structure (after) in subordinate structures depending on if the optional argument is an number or an existing object. If the last argument is omitted, the structure is added at the end of the subordinate structures (using optional (after) since 3.2/1.0).
    Supported By: records and structures
    Internal Script use only
begin undo
end undo action "script changes"
All scripts that change data are automatically undoable in GEDitCOM II by choosing the undo command after running the script, but the undo command will simply say "Undo" and you may need multiple undos to undo all changes. If you prefer a more descriptive menu item text and a single Undo command to undo everything changed by the script, you can bracket all changes with begin undo and end undo commands. The end undo command must specify the action argument, which is the text to follow "Undo" in the undo menu item text. If you use a begin undo command, you must provide the matching end undo command. The undo grouping can be disrupted by dialog boxes, meaning you should not use the display dialog or other user input commands within an undo grouping.
    Supported By: documents
    Internal Script use: (object).beginUndo and (object).endUndo (action)
    Python use: beginUndo(), endUndoAction_("script changes")
bulk reader target {} selector {} argument {}
Scripts will run faster when they can do more in a single command (e.g., get every individual rather then getting them one at a time). This command lets you read any amount of properties from a collection of objects in a single function call. It can help to increase the efficiency of long scripts. The target argument is a list of objects and selector argument is a list of properties (from the AppleScript dictionary for GEDitCOM II objects). This command will find all requested properties for each target object. The returned result will list of lists. There will be one sublist for each property in selector. Each sublist will match the length of target and will have that property for each object in target. When the data you want is not available in a property, you can set an item of selector to "evaluate" and provide argument list where the corresponding item of argument is an expression to find the data. When argument is provided, it must have the same length as selector. For items of selector that are not "evaluate", the corresponding item of argument should be an empty string.
    For example, the following script will read birth date, death date, and cause of death for every individual in the file in a single command:
tell front document
  set props to {"birth date", "death date", "evaluate"}
  set args to {"", "", "DEAT.CAUS"}
  set indis to every individual
  set bd to bulk reader target indis selector props argument args
end tell
The corresponding AppleScript to read the same data without using bulk reader would be:
tell front document
  set bd to {{}, {}, {}}
  repeat with indi in every individual
    tell indi
      set end of item 1 of bd to birth date
      set end of item 2 of bd to death date
      set end of item 3 of bd to (evaluate expression "DEAT.CAUS")
    end tell
  end repeat
end tell
In both cases, bd will be something like {{"4 JUL 1776", "15 AUG 1843", ...}, {"15 SEP 1854", "29 FEB 1904", ...},{"", "Cancer", ...}}, but the bulk reader method will get the same data faster, especially in large files.
    Supported By: documents
    Internal Script use: Not needed because internal scripts are fast without this command.
    Python use: bulkReaderSelector_target_argument_(selector,target,argument)
can link record type "SOUR"
Returns true or false if the target record for the command can link to the specified record type (by GEDCOM tag for the record type). In other words, the specified record type can "move to" the target record.
    Supported By: gedcomRecords (any type)
    Internal Script use: (object).canLink "#var",(type) set #var to "true" or "false" if can link to record type in (type)
    Python use: canLinkRecordType_("SOUR")
(object).clearContextInfo,(type)
Set the context info property of all records of a given (type) (e.g., INDI, FAM, etc.) in a document to empty.
    Supported By: documents
    Internal Script use only
(object).close [(NoYesPath)]
Close the document or the window object in (object). The optional argument only applies when object is a document. It can be "no" (or "false") to close the document without saving, "yes" (or "true") to save before closing the document, or a path to a file with extension ".gedpkg" to save document under that new name. For safety, the file at provided path must not exist (i.e., it will not overwrite existing files). Also, "yes" only works for previously saved files. Untitled files (such as after opening a ".ged" file with an OpenFile command) will only be saved if you provide a valid save path. (closing documents since 3.1b4/1.0)
    Supported By: documents and windows
    Internal Script use only
close child
Closes the front-most child window in the targeted document (e.g., a browser or family tree window) and returns the title of the window that was closed. It will not close the main document index window. If no child windows are found (i.e., the index window is the only window open for the document), nothing is closed and it returns an empty string.
    Supported By: documents
    Internal Script use: (object).closeChild ["#var"] - #var, which is optional, is set to closed window's title (since 3.2/1.0).
    Python use: closeChild()
Compress "#var",(PathToFolder)
Compresses the folder at (PathToFolder) to a zip file. The variable #var is set to the resulting zip file name, which will be folder name plus .zip and possibly with an inserted number, if needed, to avoid overwriting an existing file. Note that .gedpkg files created by GEDitCOM II are actually folders and therefore can be compressed with this command
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2/1.0)
consolidate multimedia to folder "pathToFolder" [preserve paths true/false] [change links true/false]
This command provides script control to the multimedia consolidation process in the multimedia options window. The pathToFolder must be a full POSIX path (a path with folders separated by /'s) to a folder (which need not exist yet). The two optional arguments correspond to settings for steps #3 and #4 in the multimedia consolidation process. See GEDitCOM II help for more details on multimedia consolidation and both default to true.
    Supported By: documents
    Internal Script use: (object).consolidateMultimedia (pathToFolder),[(preserve)],[(links)] (since 3.2/1.0)
    Python use: consolidateMultimediaToFolder_changeLinks_preservePaths_("pathToFolder",True,False) - use capitalized True or False in Python.
copyFile destination "/Users/myhome/path/tofile"
Copies the file linked to a multimedia object to a new location using the name provided in the destination argument. The destination file must be specified by a full POSIX path (a path with folders separated by /'s). The specified file must not exist, otherwise the command will return an error.
    Supported By: multimedia
    Internal Script use: (object).copyFile "#result",(destination) - if successful, #result will be empty. If an error, it will be "cannotCopy" if no file for copying (including multimedia as a URL link) or "copyFailed" if file found, but could not be copied (most common reasons are a file at provided path already exists or you do not have permission to write at that location) (since 3.1/1.0).
    Python use: copyFileDestination_("/Users/myhome/path/tofile")
CreateDocument
Creates a new untitled document object. Use "@doc="gcpp.frontDocument" (or gcapp.get doc,"frontDocument") to get object for the new document.
    Supported By: a direct command in internal scripts
    Internal Script use only
CreateList objName,[(item1),(item2),...]
Creates a new list object and sets objName to that list. The command can include any number of expressions and/or quoted object specifiers and they are all added to the new list (using specifiers since 3.5/1.0). Note that failed object specifiers will add text of the specifier as a string instead of causing an error. Use addObject after creating the list to validate object specifiers before adding them to the list. See here for information on working with lists.
    Supported By: a direct command in internal scripts
    Internal Script use only
CreateDictionary objName
Creates a new dictionary object and sets objName to that dictionary. See here for introduction working with dictionaries.
    Supported By: a direct command in internal scripts
    Internal Script use only
CreateScriptOutput (objName),(title),[(style)]
Creates a ScriptOutput object for creating reports when using internal scripting. The (objName) is the object name assigned to the ScriptOutput object and (title) is the title for the window when the results are opened in a report window. The optional (style) is the style of the report and can be "html" (which is the default), "monospace", or "plain text". See internal scripting of reports for more details on using ScriptOutput objects to create reports.
    Supported By: a direct command in internal scripts
    Internal Script use only
(object).css (expr)
Add the text in (expr) to the cascading style sheet (CSS) for the current ScriptOutput. All such text will be added to the report by the write command.
    Supported By: ScriptOutput
    Internal Script use only
date format full date "1 AUG 1291"
Convert any valid GEDCOM date to the user-preferred date style specified in the GEDitCOM II date settings.
    Supported By: documents, gedcomRecords (any type), or structures
    Internal Script use: use dateformat(date) string function in expressions instead
    Python use: dateFormatFullDate_("1 AUG 1291")
date numbers full date "2 JUL 1776"
Given a valid GEDCOM date, this command will return the day, month, and year for the date. The returned list will have 3 or 6 items if the date is a single date or a date range. The three numbers for each date will be day, month, and year (in that order). If the date is missing any part (e.g., no day or month), the corresponding number will be 0. If the date is not a valid date, the returned results will be an empty list with zero items.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: DateNumbers "#var",(date) - final result in #var[1] to #var[6] with #var[0] set to number of parts found
    Python use: dateNumbersFullDate_("2 JUL 1776")
date parts full date "FROM 2 JUL 1776 TO 6 JUL 1776"
Given a valid GEDCOM date, this command splits the date into parts and returns the result in a list. The returned list will have exactly five items in order {prefix, date 1, conjunction word, date 2, date comment}. For example, the above date will return {"FROM", "2 JUL 1776", "TO", "6 JUL 1776", ""}. Any missing parts will return an empty list element. For example, the date "4 JUL 1776" will return {"", "4 JUL 1776", "". "". ""}. The fifth item for "date comment" is only present in interpreted dates and it will include the parentheses. If the date is invalid, the returned list will have one one item containing an error message.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: DateParts "#var",(date) - final result in #var[1] to #var[5] with #var[0] set to 5. An invalid date will have #var[0]=1 and an error message in #var[1].
    Python use: datePartsFullDate_("FROM 2 JUL 1776 TO 6 JUL 1776")
date style full date "2 JUL 1776" with format "%d %M %y %b"
Given a valid GEDCOM date, this command will reformat the date in any style defined by the specified format. The format options are decribed below.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: DateStyle "#var",(date),[(format)] - set #var to the formatted date
    Python use: dateStyleFullDate_withFormat_("2 JUL 1776", "%d %M %y %b")
date text sdn 2455032 [with format "%d %M %y %b"]
Converts a serial day number (an integer count of days where 1 is a year around 4000 BC) to the date for that day using the optionally provided format or using the user-preferred date style in the GEDitCOM II settings (if no format is specified).
    A format is specifed with "%" codes to specify locations of various parts of the date. These codes can be separated by spaces or text (e.g., "-" or "/") that will appear in the final date. The date part codes are:     Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: DateText "#var",(sdn),[(format)] - set #var to the formatted date
    Python use: dateTextSdn_withFormat_(2455032,"%d %M %y %b")
date today
Returns today's date as a string using the user-preferred date style in the GEDitCOM II settings.
    Supported By: documents, gedcomRecords (any type), or structures
    Internal Script use: use read-only variable #today$ instead
    Python use: dateToday()
date year full date "2 JUL 1776"
Given a valid GEDCOM date, this command will return year for the date with "c", "<" or ">" to indicate approximate, before or after dates. If the date is range range, it will return "<" the year for the second date.
    Supported By: documents, gedcomRecords (any type), or structures
    Internal Script use: use dateyear(date) string function in expressions instead
    Python use: dateYearFullDate_("2 JUL 1776")
(object).delete
Delete a GEDCOM record, a GEDCOM structure, or an album from the document. You cannot delete the header record, the main submitter record, or any record marked as "locked". Note that any record or structure deleted that is in a GC List in use by the script will be removed from that list as well. But a record or structure in a list is not automatically removed from that list. If you want it removed from that list, reference it using the list, such as:
@recs = "gdoc.selectedRecords"
recs.0.delete

! instead of
@rec = "recs.0"
rec.delete
The first removes the record from the recs list while the second does not (although you could manually remove it with "recs.remove 0" if needed).
    Supported By: records, structures, and albums
    Internal Script use only
DeleteFiles (PathToFile),...
Deletes any number of files in one or more (PathToFiles)'s.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2/1.0)
description output options {"LIST", "SAY", "LINKS", "MAINLINK", "HTML", "PRON", "SEX", "BD", "BP", "DD", "DP", "MD", "MP", "FM", "SN", "CN"}
Provides a description, with customizable amount of detail, for the target record. These descriptions are fast and an easy way to fill out custom reports with details on each individual listed in the report. The description can be formated as a list:
Name: Joseph Smith
Born: 23 Dec 1805 in Sharon, VT
Died: 27 Jun 1844 in Carthage, IL
or in a narrative style:
Joseph Smith was born 23 Dec 1805 in Sharon, VT. He died 27 Jun 1844 in
Carthage, IL.
The optional output options are provided in a list with short, quoted codes. Some codes have meaning only for certain records. The meanings of the codes are:     Supported By: gedcomRecords (any type)
    Internal Script use: (object).description "#theVar",(options) where options is an valid list of the above options.
    Python use: objectDescriptionOutputOptions_(list_variable)
detach [child individual id "@I71@"] [spouse "husband"]
This command can detach a child or spouse from a family record. Both arguments are optional. The child can be specified by a reference to the child record (as above) or just using the child's record id (above could be child "@I71@"). To detach a spouse follow the spouse argument by "husband", "wife", or "both".
    Supported By: families
    Internal Script use: (object).detach "(object1)" where (object1) specfies a spouse or child in the family or can be "husband", "wife", "both", or id of any child in the family (note these options fail if an existing object name is "husband", "wife", or "both"). Only one person can be detached with each commmand.
    Python use: detachChild_spouse_(theIndividualOrID,"husband")
(object).difference "(object1)"
Both the target (object) and the single argument (object1) must be albums. This command will then remove any records in the target album that are in the other album. The album in (object1) is left unchanged.
    Supported By: albums
    Internal Script use only
display [byName "album name"] [byType "INDI"] [sorting "view"]
Displays the records in an album (entered byName, which is an album name, or byType, where type is the GEDCOM record tag such as INDI, FAM, etc.) in the main index window for the document. The optional argument sorting will additionally sort the records by the column identified with the expression given with the argument. If neither byName nor byType is specfied, the sorting option will sort the current list in the main index window.
    Supported By: documents
    Internal Script use: (object).display (byName),[(byType)],[(sorting)] - to display by type set (byName) to empty string.
    Python use: displayByName_byType_sorting_("album name","INDI","view")
(object).dropOn "(object1)"
The target will be "dropped" on the (object1). Both the target and the (object1) object must be any subclass of GEDCOM Records. The results will be identical to dragging the target record and dropping it the (object1) record. The most common uses are to "drop" sources, notes, or multimedia objects onto records. It can handle some other drops as well (see drag and drop documentation in GEDitCOM II for details are possible options).
    Supported By: gedcomRecords
    Internal Script use only
evaluate expression "BIRT.DATE"
This command evaluates the provided GEDCOM expression beginning in the target record or structure. The returned string is the result of the expression or an empty string if the data is not found.
    Supported By: gedcomRecords (any type), structures
    Internal Script use: (object).evaluateExpression "#var",(expr) - set #var to evaluated expresison in (expr)
    Python use: evaluateExpression_("BIRT.DATE")
export gedcom file path "/Users/john/Desktop/myfile.ged" with options {(pick from list)}
This commands lets scripts control the GEDCOM export process of GEDitCOM II done by using the "Export→GEDCOM Data..." menu command. The file path gives the full POSIX style (with /'s) path to the file to be saved. The options provided in a list let you control the export style. The list uses unquoted constants from the options listed below. The default option in each group (if none in the group are provided) is given in bold. Note that EDitCOM_Records/GEDitCOM_Settings/GEDitCOM_All export custom GEDitCOM II records, "Settings" adds settings for albums, and "All" adds settings and thumbnails of multimedia objects. More details on these options are in the GEDitCOM II help on exporting.
    Supported By: documents (all) and albums (except internal scripting)
    Internal Script use: (object).exportGEDCOM "/Users/john/Desktop/myfile.ged",(options) - where (options) is a list with strings matching above options (in any order and case insensitive). (since 3.2/1.0)
    Python use: exportGedcomFilePath_withOptions_("/Users/john/Desktop/myfile.ged",listVariable)- note that in Python, the defined constants have to be replaced by their hexadecimal values: char_MacOS = 0x784F7031, char_ANSEL = 0x784F7032, char_UTF8 = 0x784F7033, char_UTF16 = 0x784F7034, char_Windows = 0x784F7035, lines_LF = 0x784F7036, lines_CR = 0x784F7037, lines_CRLF = 0x784F7038, GEDCOM551 = 0x784F7039, GEDCOM551_Embedded = 0x784F7041, GEDCOM55 = 0x784F7042, GEDitCOM_Records = 0x784F7043, GEDitCOM_All = 0x784F7044, and GEDitCOM_Settings = 0x784F7045. See below for more information and an alternative.
find structures tag "PLAC" [value "Germany"] [output "references"]
Find all structures in the target record or structure with the given tag name. If the optional value is provided, find structures with the specified tag and value. If value is not provided, find all structures with that tag and any text.
    The found structures can be returned two different ways. If the optional output is "list" (or if it is omitted), the returned result will be a list of lists. The number of items in the main list is the number of structures found. For each found structure, the sublist will have the contents of the first line of the structure as the first item, and a list of numbers to find that structure in the remaining items. For example:
tell individual 1
   set places to find structures tag "PLAC"
   -- result could be {{"Boston, MA, USA", 3, 2}, {Seattle, WA, USA, 4, 1}}
end tell
The first item in the list means a PLAC line containing "Boston, MA, USA" was found at structure 2 of structure 3 of individual 1. Similarly, "Seattle, WA, USA" was found at structure 1 of structure 4 of individual 1. See the "Change Place Name" script for an example of using this output option and making use of the returned integers to change the found tags.
   If output is "references", the returned result will instead be a list of references to the found structures. For example:
tell individual 1
   set places to find structures tag "PLAC" output "references"
   -- result could be {reference to structure 2 of structure 3 of individual 1, 
   --      structure 1 of structure 4 of individual 1}
end tell
set placRef to item 1 of places
contents of placRef
The number of items in the returned list will be the number of found structures. Each item will be a reference to a structure. You can extract the items in the list to reference a structure, access or change its contents, move it elsewhere, delete it, etc.. Normally returning "references" is more useful. The "list" option is the default for backward compatibility of some scripts.
   The tag value can by one of the following special strings — INDIEvents, INDIAttributes, INDIOrdinances, or FAMEvents — and it will return all events, attributes, or ordinances for the target record. When using these special strings the value argument is ignored.
    Supported By: gedcomRecords (any type), structures
    Internal Script use: (object).findStructures objvar,(tag),[(contents)] - set objvar to a list of the found structures and always returns them as structure objects (i.e., always using "references" output and the "list" option is not available).
    Python use: findStructuresTag_output_value_("PLAC","Germany","references")
format name value "John /Smith/" [case "upper"]
Format the text provided in name value as a GEDCOM name and optionally change the case to "upper", "uppersurname", or "title". See the "Change Name Case" script for a sample use of this command.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: FormatName "#result",(value),[(case)] - set #var to the formatted name.
    Python use: formatNameValue_case_("John /Smith/","upper")
(object).get ("#var" or objName),[(attr)]
This command is mostly replaced by methods explained below, but it is still allowed and can be useful for robust error checking or debugging. The first argument defines an assignment type and must be either a quoted, valid variable name (in "#var") or valid object name (in objName). If it is neither, the command fails with an error message. The result of this command depends on the target object in (object) and the assignment type (to variable or object). The options are:
  1. If (object) is an internal scripting object and the assignment type is to an object, set objName to one of that object's "to-many" or "to-single" attributes defined by (attr). If the optional (attr) is not provided, set objName to (object).
  2. If (object) is a string or number extracted from a list or a dictionary and the assignment type is to a variable, set #var to that string or numerical value and (attr) is not used. Note 1: it easier to "get" such strings using "@" expression, but option to get strings from lists and dictionaries left in for backward compatibility (see below). Note 2: "getting" object properties requires an "@" expression and including a property as last element in (object) will cause an error.
  3. If (object) is an invalid object specifier, the command will cause an error.
  4. If none of the above apply, this command will not cause an error. Instead, if the first argument is "#var", that variable will be made "undefined." If the first argument is objName, the object name will set to None. This response can be used to validate (object) before using it in subsequent scripting:
#name="Bad Name"
indis.#name.get indi
ifDef indi
  ! commands that use indi
else
  ! commands when individual with that name was not found
endif
(This option to not cause an error since 3.2/1.0)
    In general, the get command can be done by other methods. Since 3.5/1.0, option 1 above can be replaced by object assignments that are easier to write and to understand (more similar to other languages):
indis.4.get indi                   @indi = "indis.4"
doc.families.3 husb,"husband"      @husb = "doc.families.3.husband"
^#var.get obj                      @obj = #var
Move the object specifier to right side of an assignment and append ".(attr)" if used in the command. If the original command used dereferencing with a variable, omit the caret symbol. Finally, if the final right side has any periods, it must be quoted. Option 2 above can be replaced by an "@" expression:
myList.3.get "#var"                         #var = @myList.3
myDict.key.get "#value"                   #value = @myDict.key
    The only difference between a "get" command and an object assignment is when the object specifier to the command is invalid. By option 3 above, an invalid specifier in a "get" command will cause an error. In contrast, moving an invalid object specifier to the right in an object assignment will assign the object to None instead of causing an error. Thus, use a "get" command for robust error checking and debugging or switch to an assignment method to avoid scripts stopping with errors.
    Supported By: all objects in an assignment, all objects to get attributes, and lists or dictionaries to get strings or numbers
    Internal Script use only
GetObject objName,"(object)"
This command provides the equivalent of objName = "(object)" where (object) is a quoted object specifier for the desired object (quotes can be omitted if (object) is just an object name). If (object) is not a valid object, objName will be set to None object that can be checked with ifDef or ifNDef conditionals.
    Note that since 3.5/1.0, this command can be replaced by @objName = "(object)". The GetObject command is still available but only needed if you want a script to run in versions earlier than 3.5/1.0.
    Supported By: a direct command in internal scripts
    Internal Script use only
(object).insertObject "(object1)",(index)
Inserts one object at index in the target object. (object1) must be a valid object specifier and list indices for insertion are zero based.
    Supported By: lists
    Internal Script use only
(object).insertString (expr),(index)
Inserts one string at index in the target object. (expr) must be a valid expression and indices for insertion are zero based. This command is not allowed for monospace reports. Inserting strings into a ScriptOutput object available since 3.3/1.0.
    Supported By: lists, ScriptOutput
    Internal Script use only
(object).intersection "(object1)"
Both the target object ((object)) and the single argument ((object1)) must be albums. This command will then change the target album to contain only those records that are in both albums. The album in (object1) is left unchanged.
    Supported By: albums
    Internal Script use only
(object).join "#var",[(string)]
Joins all elements in the target object (which must be a list) separated by the optional (string) (if omitted joined by empty string). To work best, all elements in the target should be strings. Non-string items will be joined as well with MacOS deciding how to represent those items as strings. The provided quoted variable, #var, is set equal to the joined strings.
    Supported By: lists
    Internal Script use only
(object).head (expr)
Add the text in (expr) to the <head> element for the current ScriptOutput. All such text will be added to the report by the write command.
    Supported By: ScriptOutput
    Internal Script use only
list ancestors [generations 6]
Opens a family tree window for the ancestors of the target individual, displays the specified number of generations, gets the listed records for that window, closes the window, and then returns the listed records. If generations is omitted, returned result uses the current value in the GEDitCOM II settings for initial generations.
    Supported By: individuals
    Internal Script: (object).listAncestors objVar,[(gens)] where (gens) is a number and objVar is set to the listed records for internal scripts (since 3.0b3/1.0)
    Python use: listAncestorsGenerations_(6)
list descendants [generations 6]
Opens a family tree window for the descendants of the target individual, displays the specified number of generations, gets the listed records for that window, closes the window, and then returns the listed records. If generations is omitted, returned result uses the current value in the GEDitCOM II settings for initial generations.
    Supported By: individuals
    Internal Script: (object).listDescendants objVar,[(gens)] where (gens) is a number and objVar is set to the listed records for internal scripts (since 3.0b3/1.0)
    Python use: listDescendantsGenerations_(6)
local string for key "PLAC"
Retrieves the string corresponding to the provided key in the current language being used in the current format. If the key if not available in the current format, the key is returned unchanged.
    Supported By: documents, gedcomRecords (any type), structures
    Internal Script use: use local(key) or string(ley) string function in expressions instead
    Python use: localStringForKey_("PLAC")
LonLatBounds (objVar),(bounds)
This command decodes the string in (bounds) for a map and sets (objVar) to a list with four items. The first two are longitude and latitude for the southwest corner and the second two are width (E-W longitude span) and height (N-S latitude span) for a bounding rectangle. Typically (bounds) is set to the content of a _BNDS custom tag used by GEDitCOM II and the command accepts all entry syles supported in GEDitCOM II. Note that input coordinates, as in GEDitCOM II, have latitude before longitude, but this command returns rectangle with longitudinal for x axis and latitude for y axis (i.e., the usual format for rectangles). If the provided (bounds) can not be decoded, the return result will a list with one item as a string explaining the error.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2/1.0)
makeFolder destination "fullpath"
Create a folder at the destination specified in "fullpath" and return YES or NO if the creating succeeds ("true" or "false" for internal scripts). All intervening folders in the path will be created if needed. For GEDitCOM, the folder must be in the genealogy workspace.
    This command can be done by targeting the "Finder" in AppleScript or by standard Python methods. It is provided for internal scripts and as a replacement method when writing scripts for GEDitCOM.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: MakeFolder "#var",(fullpath) - set #var to "true" or "false" if it succeeds (since 3.1/1.0)
    Python use: makeFolderDestination_("fullpath")
merge with record "@I71@" [force true]
This command will merge the record (specified by ID or by record reference) into the record that is the target of the command. You can only merge two records of the same type that do not have any conflicting data. The requirements to allow merging for each record type are given in the GEDitCOM II help. This command will cause an error if you try to merge incompatible records. If you want a script to merge two records that do not meet the requirements, you can specify the optional force command as true.
    Supported By: gedcomRecords (any type)
    Internal Script use: (object).mergeWith objVar,[(force)] to merge (objectVar) record into target (object). Optional (force) can be "true" to force the merge (since 3.4/1.0)
    Python use: mergeWithRecord_force_("@I71@",True)
(object).move [(before)]
Move the target object (which must be a GEDCOM structure) to before the GEDCOM structure in (before). The move is limited to within the structures for the parent object. If (before) is not found, object is moved to be the first structure. If it is not provided, the object is moved to be the last structure.
    Supported By: GEDCOM structures
    Internal Script use only (since 3.2/1.0)
(object).moveto (row),(col)
When creating monspace reports, this command moves the current position to the row and column given in (row) and (col). The values are 1-based and using 0 for either ignores that setting (i.e., changes just row or column). The row must be to valid position between header and footer (i.e., you cannot overwrite header and footer). Rows outside available rows or columns greater then allowed columns per row are ignored.
    This command can also be used with plain text reports, but the results change. If (row)>0, it inserts (row) new lines. If (col)>0, it moves that column on the current line (lines can have any number of columns). But, if the requested column is less than the length of the current line, it will start a new line and then move to that column.
    Supported By: GEDCOM structures
    Internal Script use only (since 3.5/1.0)
name parts gedcom name "John Edward /Smith/, Jr."
Split the name into three parts for text before the surname, the surname, and text after the surname and return in a list. The above example would return {"John Edward ", "Smith", ", Jr."} for those three parts. If any parts are missing (e.g., nothing after the surname), the list will still have the item, but the item will be an empty string. If the name was formatted correctly, you can always combine the three parts (item 1 of parts & item 2 or parts & item 3 of parts) or as theList as string and you will get the correct name, but without the slashes ("John Edward Smith, Jr.").
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: NameParts "#var",name - set #var[1] to #var[3] to the three name parts (and #var[0]=3)
    Python use: namePartsGedcomName_("John Edward /Smith/, Jr.")
(object).newline [num]
Insert num line feeds into a report. If optional num is not provided, one line is inserted. For monospace reports, if the number of lines runs into the footer, the footer is inserted, a new page is started with a header, and the next line will be first line on the new page.
    Supported By: ScriptOutput
    Internal Script use only
notify progress [fraction 0.8] [message "working"]
If you write a script that does many calculations and might take a while to finish, it is a good idea to inform the user of the script process. You can display a fraction and/or a message. A fraction should be between 0 and 1 to be displayed. The fraction will be converted to a percentage and displayed in the panel that GEDitCOM II shows while scripts are running. You should invoke this command periodically, such as each pass through a repeat loop, throughout the script. Alternative, you can periodically display a message. The text in the message argument will be added to the text area in the scripting panel followed by a return. To suppress the return (since 3.5/1.0), start the message with "|" character (which will be removed before display).
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: NotifyProgress (fraction),[(message)]
    Python use: notifyProgressFraction_message_(0.8,"working")
offset "#var",(s1),(c1),(target)
Finds first occurrence of string (s1) in string (target) at or after character (c1) (first character is character 1). If (c1)≤0, it finds the last occurrence of string (s1) in string (target) at or before -(c1) characters from the end of the string. The variable #var is set to the location or set to zero if (s1) is not in (target). This command was provided as an alternative to offset(string) function in expressions for use when (s1) contains back slashes. The addition of offset(s1,c1,target) in 3.5/1.0 makes this command unnecessary.
    Supported By: a direct command in internal scripts
    Internal Script use only (searching from the end since 3.2b6/1.0)
OpenFile (FileFullpath)
This command opens the .gedpkg or .ged file specified by its full path. File opening can be done by standard AppleScript; this command allows file opening in internal scripts. The open action returns to your script before the file is done reading. To access data in the new file, an internal script needs a block that waits until the file has been read:
#oldnum=@gcapp.documents.count
Repeat
  if @gcapp.opening="false" then exit
  if @gcapp.documents.count>#oldnum then break
  sleep .5
EndRepeat
This block's repeat loop continues until number of documents increases or until @gcapp.opening is false. When the number increases, the reading is done and the front document will be the newly-opened document. If @gcapp.opening turns false, the file could not be opened (e.g., invalid path or file type). Whan such as error occurs, an error message with an explanation is automatically displayed. Here the script exits, but it could provide other options.
    Note: because using this command in an internal script means you are automating some process with files, the warnings given when opening a file with corrupted records or when importing a GEDCOM file that is missing required features are not displayed. A script can can easily check for corrupted records and standard fixes to GEDCOM files do not cause any problems.
    Supported By: a direct command for internal scripts (since 3.1b4/1.0, but omitting dialogs since 3.4/1.0)
openURL destination "URLorFullpath"
Open a URL (name beginning in "http") or a file (give its full path) in the user's default browser.
    This command can be done by standard AppleScript or Python methods. It is provided for use in Internal Scripts and as a replacement method when writing scripts for GEDitCOM.
    Supported By: documents, gedcomRecords (any type), structures, or as a direct command for internal scripts.
    Internal Script use: OpenURL (URLorFullpath) (since 3.1/1.0)
    Python use: openURLDestination_("URLorFullpath")
(object).out (expr)
(object).out text1,[col1,text2,col2,...]
(object).out "(list)"
The various forms of this command add output for a report to a ScriptOutput object. Adding output to html reports or plain text] reports can use only the first form or a command with only a single expression. That (expr) can be any text for the report. To start new lines in the report use return in the expression (and not "\n" within a string).
    All three command options can add output to monospace reports. The first option, with a single argument, just inserts that text at the current location. You can use the moveto command to set a position any place on the page and then a single-argument command to insert that text. Note that prior to 3.5/1.0, a single argument command for monospaced reports was treated like multi-argument method described next which filled the rest of the line with spaces. Old scripts might need a newline command after a single-argument out command now.
    The second option, with more than one argument, provides pairs of arguments for text and column number. The output for each (text,col) pair is as follows:     The third form is identical to the second form except that the (texti,coli) pairs can be added to a list first and then the command provides just the list object as a single argument.
    Supported By: ScriptOutput
    Internal Script use only
(object).pop ("#var" or objName)
The command will get the last element of the target object in (object), which must be a List, and will remove that element from the list. If the element is a string, the variable #var will be set to that element. If it as object, the objName will be set to that element. If the list is empty, this command will not cause an error. Instead, if the first argument is "#var", that variable will be removed from the list of variables. If the first argument is objName, that object name will set to None.
    Supported By: Lists
    Internal Script use only
populate album "album name"
This command will send records associated with the current front window to the album with the specified name (a new album with a generic name will be created if no album by the specified name is found). The records sent will depend on the type of front window. The most common uses are to send all records in family tree windows to an album.
    Supported By: albums
    Internal Script use: (object).populate - where (object) must be an existing album and no need to provide a name (because it will use album that is the target of the command)
    Python use: populateAlbum_("album name")
PreChecks (name),[(minVersion)],[(minBuild)],[(minGCVersion)],[(minGCbuild)]
Common tasks at the start of internal scripts are to verify that the user has a version of GEDitCOM II that can run this script and that a document is opened. This command automates those checks. The first argument is the script (name) name. It is required, but it is only used if any error message is displayed.
    All extensions have an option to check version number too, but these additional checks are often needed if the extension has more than one script and those scripts require different version numbers or some scripts require specific build numbers. If this extra checking is not needed, omit all arguments besides (name) and the check on version number is skipped.
    Internal scripts always require version 3.0, of GEDitCOM II but if your script uses an internal scripting option added in a later version of GEDitCOM II enter that higher number in (minVersion) as floating point number (x.y). The script will run only in (minVersion) or newer. If the script needs a feature added in a higher build of that version, enter that requirement in (minBuild) (if omitted, the default is 1). Note that although internal scripting first appeared in 3.0, build 1, a lot was changed in 3.0, build 2. To avoid documenting all those changes, if you request any version before 3.0, build 2, this check is changes to requiring 3.0, build 2. Features added after 3.0, build 2 will be listed as such in this documentation.
    Most scripts can be written to work in both GEDitCOM II and the AppStore version called GEDitCOM (hopefully coming soon). For scripts that work in both, you can add version requirements for GEDitCOM in (minGCVersion) and (minGCbuild). These will be used when someone is using GEDitCOM, while (minVersion) and (minbuild) will be ignored.
    Finally, most scripts also work on a genealogy document. This precheck will make sure at least one document is opened. Note that it does not return the opened document, thus most internal scripts will begin with:
PreChecks #scriptName,3,1,1,1
@gdoc = "gcapp.frontDocument"
This first line does all prechecks and supports both GEDitCOM II and GEDitCOM. If they fail, the script displays the reason and stops. If all is OK, the internal script can continue and fetch the front document with the get command. The document is guaranteed to be available.
    Supported By: a direct command in internal scripts
    Internal Script use only
print [with properties {starting page:"1"}] [with/without print dialog]
This command prints the front window for a document (and the command can only be sent to documents). The allowed properties are defined in the print settings property in the scripting dictionary. For internal scripting and python, the property names are NSCopies, NSMustCollate, NSFirstPage, NSLastPage, NSPagesAcross, NSPagesDown, NSPrintTime, NSFaxNumber, and NSPrinterName. Unfortunately, MacOS may not honor these settings, especially when printing with a dialog.
    One issue with printing is that control will return to your script before printing actually occurs. In some scripts, this timing may cause problems. To have the script wait for printing to finish, you can use the following procedure:
tell front document
  show browser individual 1
  print with print dialog
			
  -- wait until browser has printed
  repeat
    if printing is false then
      exit repeat
    end if
  end repeat
end tell
First you open a browser window (so a record can be printed) and then send print command to the document. The repeat loop causes the script to wait until the document printing property changes from true (meaning printing is still processing) to false (meaning GEDitCOM II is finished printing, although the physical print out may still be in a printer queue).
    Curiously, the following more compact repeat loop to wait for printing does not work:
  repeat while printing is false
  end repeat
because AppleScript apparently ignores loops containing no commands (perhaps a minor bug in AppleScript?). The work around is the method above that checks printing status within the loop.
    Supported By: documents
    Internal Script use: (object).print [(dialog)],[(setDict)] to print front window target document. Optional (dialog) can be "false" to skip print dialog. Optional (setDict) can be dictionary object of print settings (since 3.4/1.0)
    Python use: gedit.print_printDialog_withProperties_(gdoc,True,None) - notice that you have to send the command to the application object and provide the document that is the target of the command as the first argument in the function. Futhermore, the print dialog argument, which is with or without in AppleScript, is True or False in Python.
(object).putPasteboard [(string)]
Puts the object on the MacOS pasteboard in a custom style that can be read by other internal scripts using the ReadPasteboard command. To put Lists on the pasteboard, the list must contain only strings, numbers, GEDCOM Objects or other Lists (and such lists can contain only the same types of elements). If the optional (string) is provided, the list is first converted to a string (as in the join command) and that string is put on the pasteboard. Note that strings on the pasteboard can be pasted into other applications while the custom style used for lists without (string) cannot.
    To put Dictionaries on the pasteboards, the objects in the dictionary can only be strings, numbers, or GEDCOM Objects. If optional (string) is used for a dictionary, it is ignored.
    A command to put a list or dictionary that does not meet these limitations will cause an error. See the ReadPasteboard command to see the format of data recovered from the pasteboard.
    Supported By: Lists and Dictionaries
    Internal Script use only (since 3.2/1.0)
ReadPasteboard ("#var" or objName)
If the first argument is a valid object name (in objName) and the pasteboard has a custom pasting of a List or Dictionary, objName will be set to the recovered object as explained below. If instead, the first argument is a valid variable name (in "#var") and the pasteboard has a string (from GEDitCOM II or from any other application), #var will be set to that string. If neither of the above two cases apply, #var will be undefined or objName will be set to None type (depending on which was in the first argument).
    Before GEDCOM Objects are put on the pasteboard, they are converted to a format acceptable to MacOS pasteboards — they are converted to the list of lists given by the gedcomArray attribute of GEDCOM objects. Pasted Lists will be read as a new list object and pasted Dictionaries as a new dictionary object. Note that gedcomArrays corresponding to pasted GEDCOM objects in the main list or in objects of dictionaries will be formatted as a list of GC lists but those for GEDCOM objects inside lists in the main list will be formatted instead as a GC list of GC lists.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2/1.0)
refresh formats
refresh scripts
Refreshes the "Extensions" menu. There are two commands because prior to version 2.0, there were two menus needing refreshing. Since version 2.0, these commands are identical.
    Supported By: application, documents, or a direct command in internal scripts
    Internal Script use: RefreshFormats or RefreshScripts (since 3.4/1.0)
    Python use: refreshFormats()
(object).remove (index/"(object1)")
Remove item at (index) from a list or remove record in (object1) from an album. List items use zero-based numbering.
    Supported By: lists and albums
    Internal Script use only
(object).removeValueForKey (key)
Remove value in a dictionary corresponding to (key) (which can be any valid expression).
    Supported By: dictionaries
    Internal Script use only
replace "#var",(s1),(s2),(target)
Replaces every occurrence of string (s1) in string (target) with string (s2). The variable #var is set to the resulting string. This command was provided as an alternative to replace(string) function in expressions for use when (s1) or (s1) contain back slashes. The addition of replace(s1,s2,target) in 3.5/1.0 makes this command unnecessary.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2/1.0)
RevealInFinder (path)
Reveals the file at full path (path) using the Finder (that path can contain "~" to indicate home directory). If (path) is a file, it tries to "double click" on the file opening in its preferred application. If (path) is a a folder, that folder opens in a Finder window. If these two options fail, it tries to open the parent folder in a Finder window. If all options file, an error occurs.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2/1.0)
run script at path "/Path/to/script"
Runs the extension or script at the provided full path (POSIX path with /'s). The script can be an extension (file ending in gplug) or an AppleScript or Python script.
    Supported By: application, documents, gedcomRecords (any type), and structures
    Internal Script use: Not implemented (or needed)
    Python use: runScriptAtPath_("/Path/to/script")
safe html raw text someText [insertPs "all"] [reformat links { INDI:"I%@.html"}]
When writing scripts that create html files, it is important to insure that text included from the GEDCOM file be formatted well for such files. You can pass any text to this command, such as text from a notes record. If that raw text is plain text, this command will check for certain special characters and convert them to html entities (e.g., <, >, ", and & are converted to &lt;, &gt;, &quot;, and &amp;).
     If the input text has line breaks, you may want those line breaks to appear in the html output. To achieve this goal you can use the insertPs argument. If the argument is "all", it will surround the text in <p> and </p> elements and replace each line break with </p><p>. Thus each line in the raw text will be a paragraph in the html output. If insertPs is "interior", the </p><p> elements will still be inserted at line breaks, but the output will not be surrounded by <p> and </p> elements.
    If the raw text is html text surrounded by <div> and </div> elements, it will be assumed to be valid html text and returned unchanged, except for internal links. Because GEDitCOM II allows such html text to link to internal records (e.g., using <a href="//@I342@">John Smith</a>), this command will, by default, remove such links and leave the text (e.g., John Smith). By using the reformat links argument, you can optionally change the links rather than remove them. The reformat links argument should provide an AppleScript record that can include format strings by GEDCOM Record tag type. If an internal link refers to an record type included in the AppleScript record, the link will be changed to the provided string with the place holder "%@" replaced by the GEDCOM Record ID without the @ signs. The above example for individual records of "I%@.html" would convert the above example link to be <a href="II342.html">John Smith</a> (which happens to be how it is used in the Web Site Export). If the provided AppleScript record has no item for a linked GEDCOM record, that link will be removed rather than reformatted.
    Supported By: documents, gedcomRecords (any type), structures (but not by application), or a direct command in internal scripts
    Internal Script use: SafeHTML "#theVar",(someText),[(insertPs)],[(relink)] - optional (relink) is a dictionary object with keys for record types and their values for replacement format (since 3.1/1.0)
    Python use: safeHtmlRawText_insertPs_reformatLinks_(someText,"all",{'INDI':"I%@.html"})
SafeTex "#safe",(expr),[(special)]
When writing extensions that copy text in genealogy files to a document intended to be typeset using LaTeX, it is crucial to be sure the copied text does not contain any characters that disrupt the LaTeX typesetting process. This command converts the text in (expr) to safe text for a LaTeX document and sets #safe (passed in first argument) to that safe text. The process escapes certain standard characters needed by LaTeX, uses a "verbatim" mode to insert certain LaTeX elements, puts some characters in math mode, and converts all double quotes to LaTeX method for double quotes.
    In addition to above tasks, this command replaces certain unicode characters known to cause problems in LaTeX with safe alternative characters. The default replacements are for non-breaking spaces, a unicode line separator, a white bullet, and two non-printing, hidden characters. These options might not cover all unicode characters that can cause problems in LaTeX. If you find other characters that cause problems, you can add them to list of special replacements using the optional third argument. Sample code would be
   CreateList reps,hexchar("25e6"),hexchar("a0")
   CreateList repsto,hexchar(2202),"~"
   CreateList special,reps,repsto
   SafeTex "#safe",#expr,special
The optional (special) must be a list that contains exactly two other lists that have identical numbers of strings. The single-character strings in the first list are the unicode characters to be replaced. The corresponding strings (which can be any length) in the second list are the strings the replace each character. The above code replaces white bullet and non-breaking space with a black bullet and LaTeX "~" used for non-breaking spaces.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2b6/1.0)
(object).save [(CopyPath)]
If (CopyPath) is omitted, this command saves the target document object. If the document has not been saved before, the user is given a standard "Save File" panel to choose a save location. If (CopyPath) is provided, it must be full path to a valid save location. A copy of the file will be saved to that location and the original will left unchanged (i.e., remain in its current state, which might include unsaved changes).
    If current document is saved or copied, the script will wait until the save is complete before returning control to the script. But, if user is given a "Save File" panel, the command will exit when that panel starts and before the user has chosen where to save the file (or maybe decides to cancel the save). Such a save process can be tracked as follows:
gdoc.save
Repeat
  sleep 0.1
  if @gdoc.saving is false
    break
  endif
EndRepeat
if @gdoc.path=""
  ! This result means the user canceled the save process
  exit
endif
! The save completed
    Supported By: documents
    Internal Script use only (since 3.2/1.0)
sdn range full date "AUG 1947"
Returns the minimum and maximum serial day numbers for the date or date range listed in the full date argument. Serial day numbers are an integer count of days where 1 is a year around 4000 BC; they are handy for date calculations. The returned result will a list of two numbers. If the provided date is invalid, the returned result will be {0,0}.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: SDNRange "#var",(date) - sets #var[1] and #var[2] to the range (and sets #var[0]=2)
    Python use: sdnRangeFullDate_("AUG 1947")
(object).set (property),(expr)
Set the (property) of the object defined by (object) to the evaluated expression in (expr). Any property listed for any of the scripting objects that is not marked "r/o" (for read only) can be set with this command. Any object's "to-single" attribute marked as "settable" can also be set where (expr) must be an object name for the expected type of object.
    Since 3.5/1.0, an easier way to set (property)s that are strings is to use an '@' expression assignment command. The set command still works and is needed to set "to-single" attributes of objects.
    Supported By: any object with non-read-only properties
    Internal Script use only
(object).setObjectForKey "(object1)",(key)
(object).setStringForKey (expr),(key)
(object).setNumberForKey (expr),(key)
These three commands set a single key-value pair in a dictionary object ((object) must be a dictionary). Three commands are available to add three types of values using a (key), which can be any string or numeric expression. The first one adds any valid object to the dictionary. The other two add any valid expression (in (expr)) to the dictionary. The main use for setNumberForKey is in scripts that will later use the keysSortedByNumericValues relation of the dictionary.
     Note that a short cut for setStringForKey is to using an assignment command:
@myDict.key = expr
@myList.3.key = expr
to set (key) to string value of any expression. The left side either references the dictionary or a dictionary extra from a list. It can note use any more-general object specifiers.
    Supported By: dictionaries
    Internal Script use only
show ancestors [generations 6] [tree style chart/outline]
Opens a family tree window for the ancestors of the target individual and displays the specified number of generations in either a chart or an outline. If either argument is omitted the new tree will use the current value in the GEDitCOM II settings for initial generations and view mode. Note: to open a window for purpose of getting listed records, use list ancestors instead.
    Supported By: individuals
    Internal Script: (object).showAncestors [(gens)],[(style)] where (gens) is a number and (style) can be "chart" or "outline'.
    Python use: showAncestorsGenerations_treeStyle_(6,chart/outline) - note that in Python, the defined constants have to be replaced by their hexadecimal values: chart = 0x74724348 and outline = 0x74724F55. See below for more information and an alternative. If you need to access the new tree window in MacOS Ventura or newer, follow this command by calling WaitForWindow().
show browser
Show record browser for the target gedcom record or report.
    Supported By: gedcomRecords (any type), reports
    Internal Script use: (object).showBrowser - show browser window for the target object (since 3.2/1.0)
    Python use: showBrowser() - if you need to access the new browser window in MacOS Ventura or newer, follow this command by calling WaitForWindow().
show browserpane with id "paneID"
Show record browser for the target gedcom record and open in the pane indicated by the paneID. If no such ID, the default pane opens. Note that pane IDs are set by the current browser style and may differ from the pane names.
    Supported By: gedcomRecords (any type), reports
    Internal Script use: (object).showBrowser (paneID) - show selected pane in browser window for the target object
    Python use: showBrowserpaneWithId_() - if you need to access the new browser window in MacOS Ventura or newer, follow this command by calling WaitForWindow().
show descendants [generations 6] [tree style chart/outline]
Opens a family tree window for the descendants of the target individual and displays the specified number of generations in either a chart or an outline. If either argument is omitted the new tree will use the current value in the GEDitCOM II settings for initial generations and view mode. Note: to open a window for purpose of getting listed records, use list descendants instead.
    Supported By: individuals
    Internal Script: (object).showDescandants [(gens)],[(style)] where (gens) is a number and (style) can be "chart" or "outline'.
    Python use: showDescendantsGenerations_treeStyle_(6,chart/outline) - note that in Python, the defined constants have to be replaced by their hexadecimal values: chart = 0x74724348 and outline = 0x74724F55. See below for more information and an alternative. If you need to access the new tree window in MacOS Ventura or newer, follow this command by calling WaitForWindow().
Sleep seconds
Pauses an internal script for provided number of seconds. Other scripting methods can use their built-in sleeping options.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.0b3/1.0)
    AppleScript use: delay seconds instead.
    Python use: import time and then use time.sleep(seconds).
(object).sort [(key1),(type1),(key2),(type2)]
Sorts the items in (object), which must be a list. If the command has no arguments, the list items are sorted by case-insensitive comparisons. All items must be strings.
    If the command has 1 to 4 optional arguments, all items in the list must be dictionaries and the sorting is done by comparing values associated with the keys where (key1) is the primary sort criterion and if (key1) values are the same those items are sorted using (key2) values. The (type1) and (type2) arguments can be "numeric" to sort values numerically or any other text (or omitted) to use case-insensitive comparisons. The values should be strings or numbers. An error will result when sorting dictionaries if any item in the list is not a dictionary or if any dictionary lacks either key needed for sorting. Sorting of dictionaries available since 3.3/1.0 (some bugs with optional arguments and dictionaries fixed in 3.5/1.0).
    Supported By: lists
    Internal Script use only
sort data the children/the events/the spouses/the multimedia
Will sort the children in a family (by birthdate), all events for an individual or family (by event date), all spouses for an individual (by marriage date), or all level 1 multimedia objects (by date in the object's record).
    Supported By: individuals, families
    Internal Script use: (object).sortData (type) - where (type) is any of the types listed above, but without the word "the".
    Python use: sortData_(the children/the events/the spouses) - note that in Python, the defined constants have to be replaced by their hexadecimal values: 'the children' = 0x736B4348, 'the events' = 0x736B4556, 'the spouses' = 0x736B5350, and 'the multimedia' = 0x736B4D4D. See below for more information and an alternative.
soundex for text "string"
Will find the SoundEx code for the provided text.
    Supported By: documents, gedcomRecords (any type), structures
    Internal Script use: use soundex(text) string function in expressions instead
    Python use: soundexForText_("string")
(object).subList objName,start,[end]
The target object (in (object)) must be a list or GC list. This command creates a new list, which is stored in objName, containing elements from index start to index end-1 (note the first element in a list is at index 0). If optional end-1 is omitted, the sublist will be from start to the end of the list.
    Supported By: lists and GC lists
    Internal Script use only
SubProcess "#var",args,[directory,environment]
Runs a subprocess and returns text output in #var (which must be quoted variable name). The second argument, args, must be a list whose first item is a command that can be run on a command line and any remaining items are arguments or options. For example, to get a list of files in a directory, you could use args = ["ls", "-la"] where first item is Unix command to list files and second is option to output one file per line with detailed information. The two optional arguments can provide a working directory and shell environment variables for the command line task. If not provided, the working direction is the disk's root directory. The path to the directory can use "~" to refer to user's home directory. The environment must be a dictionary with shell variables as keys with their values as string. Most common is to set PATH variable used to locate the command. If environment is not provided, the process will use the one assigned to the running GEDitCOM II application.
    If the process fails, #var will have error details and its first line will be "ERROR". A common error is "Command not found" when the desired command is not in the assigned PATH for the environment. If you get such an error, either use environment with PATH variable set to include the path to your command or specify the command by its full path (e.g. "/opt/local/bin/svn" for svn installed using MacPorts).
    Note that if the command writes to disk, you must make sure GEDitCOM II is configured to have full disk access or at least have access to folders used by the command. Full disk or folder access can be granted in MacOS "Privacy & Security" settings.
    Supported By: a direct command in internal scripts
    Internal Script use only (since 3.2b6/1.0)
(object).union "(object1)"
Both the target object ((object)) and the single argument ((object1)) must be albums. This command will then change the target album to be a union of the records in the two albums. The album in (object1) is left unchanged.
    Supported By: albums
    Internal Script use only
uniqueFile destination "fullpath"
Given the full path name to a file (or directory), this will return a unique file name for the same folder. If the suggested file does not exist, the input name comes back. If it does exist, the returned name will append a number (between the file name and its extension) that guarantees the file does not exist.
    This command can be done by targeting the "Finder" in AppleScript or by standard Python methods. It is provided for use in internal scripts.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: UniqueFile "#var",(fullpath) - set #var to full path to the unique file name (since 3.1/1.0)
    Python use: uniqueFileDestination_("fullpath")
user choice prompt "Prompt Text" list items {"item 1",";item 2"} [title "Panel Title"] [buttons {"OK","Cancel"}] [multiple false]
Will display a dialog box where the user can select one item from the provided list items. To have an item preselected, use a semicolon (";") as the first character (the semicolon will not be displayed). If no item is marked as selected, the first item will be selected. The required prompt is displayed above the list box to explain the requested selection (it can be any length and use multiple lines). The optional title is displayed in the title bar of the window. The optional buttons can change the text of the default "OK" and "Cancel" buttons and optionally add a third button. The optional multiple argument can be true or false to allow selection of multiple items (if it is false and more than one item is marked as selected, only the first one will be selected; default is false).
    The returned result of this command is a list with three items. The first item is the text of the button that was clicked. The second item will be another list with the text of the one or more items selected by the user. The third item will be another list with indices of the one or more items selected by the user (the first item is index=1).
    This command can be done with the choose from list command in AppleScript. It is provided in GEDitCOM II for use in Python scripts or as an alternative to the AppleScript version in AppleScripts.
    Supported By: documents, gedcomRecords (any type), structures, structures, or a direct command in internal scripts
    Internal Script use: UserChoice "#var",(prompt),(list),[(title)],[(multiple)],[(btn1)],[(btn2)],[(btn3)] - where (list) specifies a valid list object. Set #var[1] to text of clicked button, #var[2] to #var[1+n] to text of selected items, and #var[2+n] to #var[2n+1] to selected indices (also sets #var[0]=2n+1)
    Python use: userChoiceListItems_prompt_buttons_multiple_title_(["item 1","item 2","item 3"], "Prompt Text", ["OK","Cancel"], False, "Panel Title") - use capitalized True or False in Python.
user input prompt "Prompt Text" [initial text "default text"] [title "Panel Title"] [buttons {"OK","Cancel"}]
Will display a dialog box where the user can enter one line of text. The required prompt is displayed above the text field to explain the requested input (it can be any length and use multiple lines). The optional initial text is placed in the text field (it can only be a single line). The optional title is displayed in the title bar of the window. The optional buttons can change the text of the default "OK" and "Cancel" buttons and optionally add a third button. The returned result of this command is a list with two items. The first item is the text of the button that was clicked. The second item is the text entered by the user in the text field.
    This command can be done with the display dialog command in AppleScript. It is provided in GEDitCOM II for use in Python scripts or as an alternative to the AppleScript version in AppleScripts.
    Supported By: documents, gedcomRecords (any type), structures, structures, or a direct command in internal scripts
    Internal Script use: UserInput "#var",(title),[(prompt)],[(initialText)],[(btn1)],[(btn2)],[(btn3)] - set #var[1] to text of clicked button and #var[2] to text entered by the user (also sets #var[0]=2)
    Python use: userInputPrompt_buttons_initialText_title_("Prompt Text", ["OK","Cancel"], "default text", "Panel Title")
user openFile [start "/Users/nairnj/Desktop"] [extensions {"ged", "gedpkg"}] [title "Open"] [prompt "Pick a genealogy file"]
Will display standard MacOS panel for user to select an existing file. The start argument can be used to define the initially selected folder and/or file (if not provided for GEDitCOM the start location will be genealogy workspace folder). The extensions list means the user can only select files with those extensions (if omitted, any file can be selected). The title is title for the open panel window (this title is not displayed in new MacOS's, but kept as parameter for compatibility). The prompt is a string that will appear in the window to help the user.
    When done, the command will return the full POSIX path to the selected file (or empty if canceled).
    This command can be done with the choose file command in AppleScript. It is provided in GEDitCOM II for use in Internal or Python scripts or as an alternative to the AppleScript version in AppleScripts.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: UserOpenFile "#var",[(extensions)],[(prompt)],[(start)],[(title)],[(multiple)] - sets #var to the selection (or empty if canceled). (extensions) must be a List. Any omitted or empty arguments are ignored (since 3.1/1.0). If (multiple) argument is "true", user can select multiple files (since 3.3/1.0). When done, #var[0] is set to number of files selected and the paths are in #var[1], #var[2], etc. (note that #var is set to first selected file, or empty if canceled, for backward compatibility). The option to select multiple files is currently only available for internal scripts.
    Python use: userOpenFileExtensions_prompt_start_title_(["ged","gedpkg"], "Pick a genealogy file", "/Users/nairnj/Desktop", "Open")
user openFolder [start "/Users/nairnj/Desktop"] [title "Open"] [prompt "Pick a genealogy file"]
Will display standard MacOS panel for user to select an existing folder. The start argument can be used to define the initially selected folder (if not provided for GEDitCOM the start location will be genealogy workspace folder). The title is title for the open panel window. The prompt is a string that will appear in the window. When done, the command will return the full POSIX path to the selected folder (or empty if canceled).
    This command can be done with the choose folder command in AppleScript. It is provided in GEDitCOM II for use in Internal Scripts and Python scripts or as an alternative to the AppleScript version in AppleScripts.
    Supported By: documents, gedcomRecords (any type), structures, or a direct command in internal scripts
    Internal Script use: UserOpenFolder "#var",[(prompt)],[(start)],[(title)] - sets #var to the selection. Any omitted or empty arguments are ignored (since 3.1/1.0).
    Python use: userOpenFolderPrompt_start_title_("Choose any folder", "/Users/nairnj/Desktop", "Open")
user option title "Main text" [message "Subtitle text"] [buttons {"OK","Cancel"}]
Will display a dialog box to the user with one to three buttons (provided in the list). The title is in bold and main text of the window. The message appears below the title to provide extra information. The first button is the default button and the buttons appear right to left. The returned result of this command is the text of the clicked button.
    This command can be done with the display dialog command in AppleScript. It is provided for use in Internal Scripts or Python scripts (or as an alternative to the display dialog in AppleScripts).
    Supported By: documents, gedcomRecords (any type), structures, structures, or a direct command in internal scripts
    Internal Script use: UserOption "#var",(title),[(message)],[(btn1)],[(btn2)],[(btn2)] - sets #var to text of the clicked button
    Python use: userOptionTitle_buttons_message_("Main text", ["OK","Cancel"], "Subtitle text")
user saveFile [start "/Users/nairnj/Desktop"] [extensions {"ged", "gedpkg"}] [title "Save"] [prompt "Save file to this location"]
Will display standard MacOS panel for selecting file name and location for saving a file. The start argument can be used to define the initially selected folder and/or file name (the file need not exist and you can supply just the name if the start folder is not important). The extensions list means the user should save to files with those extensions; if they choose another extension, they will be prompted to use the first extension in the list. The title argument is the title for the save panel. The prompt is a string that will appear in the window. If the selected file already exists, the user will be asked to confirm that it is OK to replace that file. When done, the command will return the full POSIX path to the selected file (or empty if canceled).
    This command can be done with the choose file name command in AppleScript. It is provided in GEDitCOM II for use in Internal Scripts or Python scripts or as an alternative to the AppleScript version in AppleScripts.
    Supported By: documents, gedcomRecords (any type), structures
    Internal Script use: UserSaveFile "#var",[(extensions)],[(prompt)],[(start)],[(title)] - sets #var to the selection. (extensions) must be a List. Any omitted or empty arguments are ignored (since 3.1/1.0).
    Python use: userSaveFileExtensions_prompt,start_title_(["ged","gedpkg"], "Save file to this location", "/Users/nairnj/Desktop", "Save")
user select [by type "INDI"] [from list (IDs or Refs)] [prompt "Select a record"]
Will display a window of records and let the user select one from the list. The record to display can be specified by type (e.g., "INDI" for all individuals) or by a list of record IDs or references to records (one must be provided). The optional prompt is displayed in the window for selecting a record. This command merely starts the selection window. To wait for user selection, you need the following loop:
user select by type "INDI"
repeat
   set pr to picked record
   if pr is not "" then
      exit repeat
   end if
end repeat
The loop waits until the picked record property is set and no longer an empty string. Once set, it will be a reference to the selected record or be "Cancel" if the user canceled the selection process.
    Supported By: documents
    Internal Script use: (object).UserSelect (type),[(prompt)] or (object).UserSelect "","(list)",[(prompt)] - select by (type) or by (list) object of IDs (when (type) is an empty string). As in AppleScript, the command merely starts the window and the script must wait in a loop until the user makes a selection. The loop in an internal script is:
gdoc.UserSelect "INDI"
Repeat
  @res = "gdoc.pickedRecord"
  if @res.count>0 then break
EndRepeat
if @res.0="Cancel" then exit
@rec = "res.1"
When done, rec will be the selected record.
    Python use: userSelectByType_fromList_prompt_("INDI",None,"Select an individual"). As in AppleScript, the command merely starts the window and the script must wait in a loop until the user makes a selection. The loop in Python is:
gdoc.userSelectByType_fromList_prompt_("INDI",None,prompt)
while True :
    rec = gdoc.pickedRecord().get()
    if rec != "" : break
When done, rec will be a reference to the selected record or "Cancel" if user canceled the selection process.
(object).valueForKey ("#var" or objName),(key)
Fetches the value from a dictionary corresponding to (key), which is any valid expression. If the value is a string or a number, set #var (which must be a quoted variable name starting in "#") to that value. If the value is an object, set objName (which must be a valid object name) to that object. If value type and the first argument are mismatched (e.g., using objName when value is a string or number or using "#var" when value is an object) or if (key) is not in the dictionary, then "#var" will be undefined or objName will be set to None type. Such results can be checked using ifDef conditionals (note: before 3.2/1.0, a mismatch in value type and first argument caused an error).
    Supported By: dictionaries
    Internal Script use only
(object).write ("(object1)" or "#var"),[(preface)]
Scripts that use ScriptOutput should end the script with this command and its result depends on the type or report and on whether the first parameter is (object1) or "#var" :
  1. For html reports, this command will insert elements added with css or head commands and start the body of the report with the optional (preface) (an option provided in case information for the preface is not known until done adding other text). Note that an optional (preface) will be ignored for plain text and monospace reports.
  2. For plain text reports this command concatenates all text added to the report.
  3. For monospace reports, this command flushes the last page footer and then concatenates all text added to the report.
The compiled report is then output as follows. If first parameter is (object1) for a document, the results will open in a report window for that document. Html reports will display the html content. Plain text and monospace reports will display using the report's monoFont and monoSize settings.
    If first parameter is "#var", that variable will be set to text content of the report (for html report that text will be formatted suitable to export to an html file). The most common reason for the "#var" option is to export the results to a file. Here is sample code:
rpt.write "#report"
CreateList exts,"txt"          ! use "html" for html report
UserSaveFile "#file",exts
if #file!=""
  Export #report,#file
endif
    Supported By: ScriptOutput
    Internal Script use only

Notes

Defined Constants in AppleScript
Any constants defined in GEDitCOM II's AppleScript dictionary (e.g., chart, outline, etc.) have to referenced by their underlying numeric code in Python scripts rather then their defined name. The hexadecimal constants relevant to various commands above are listed with those commands. Alternatively, you can use the GCConstant() utililty subroutine (which is in the module for Python) and refer to them by name. With this subroutine, you refer to constants using GCConstant("chart"), etc., passing the case-sensitive name defined in the dictionary as a string.