Clip Manager 5 AppleScript Support

From myFMbutler wiki
Jump to: navigation, search

Main Page > Clip Manager 5 > AppleScript

The AppleScript support in Clip Manager 5 is not finalized yet.

As more commands become available, they will be documented here.

Contents

AppleScript Changes in Clip Manager 5

In Clip Manager 5 we don't load the clip anymore in the Clip Manager window, but in a separate space in memory. There are a few advantages:

  • AppleScript is faster
  • Your script can run, with a closed window.
  • Your AppleScript don't interfere with the users clip.
  • No dialogs can pop-up in between.
  • Doesn't change the user preferences (Auto Paste, search options)

All AppleScript commands are no longer making use of the clip in memory, except for these mentioned in the "Obsolete" section. This commands will still working, but we recommend you to avoid them.

If you are missing a command, please leave a reaction on http://support.myfmbutler.com.

Overview

* New | ** Obsolete

C

G

I

N

O

P

R

S

Commands

GetAutoPaste

Description

Gets the status of the AutoPaste flag. If the AutoPaste set was not set by the command "SetAutoPaste" before, this command will return the user preference.

Return value

Boolean

GetClip

Description

Get the clip is in the clipboard as UTF-8

Return value

Text: The clip XML contents

GetClipClass

Description

Get the class of the loaded clip (in memory).

Return value

Text: The class of the clip, being “XMLO”, “XMFD”, “XMTB”, “XMSC”, “XMSS” or “XMFN”

GetClipContents

Description

Get clip content as text from currently loaded Clip (in memory).

Return value

Text: The contents of the loaded clip (should be UTF-8 text)

GetClipMethod

Description

Gets the “method” the loaded clip was created.

Return value

Text: The method:

  • “new” for a new clip
  • “file” for a file based clip
  • “history” for a clip history item
  • “snippets” for a snippets based clip

Note: "Session" does not longer exists.

GetClipPath

Description

Get the path of a file based clip

Return value

File: the path of the clip

GetClipsFolderPath

Description

Get the path of Clip Manager clips Note: This command will be available in the next release.

Return value

File: Clip Manager clips

isChanged

Description

Returns if the loaded clip has been changed or not

Return value

Boolean: true is the clip has been modified

NewClip

Description

Clears the currenly loaded clip and creates a new empty clip.

OpenClip

Description

Loads a clip file into the memory.

Parameters

File: The path to the clip file

Return value

Boolean: true if the file has been loaded successfully

ReplaceAll

Description

Replaces the first string in the given list by the second string in the given list. FindEntireWord is no longer supported in the current version of Clip Manager 4. This may change in a future release.

Parameters

  • Text: the string to search
  • by: Text: the string to replace in the the search string
  • CaseSensitive: Boolean: should the search be case sensitive (optional)
  • FindEntireWord: Boolean: find entire words only. This option is ignored since this is not supported in the current version of Clip Manager (optional)
  • UsingRegularExpression: Boolean: find and replace using a regular expression(optional)
  • Greedy: Boolean: use the "greedy" option in regular expression(optional)
  • DotMatch: Boolean: use the "dot match" regular expression option(optional)
  • TreatingTargetAsOneLine: Boolean: regular expression option treating the target as one line(optional)

Return value

Boolean: True if no errors occurred and something is replaced.

SaveClip

Description

Saves the loaded clip to the file specification

Parameters

File: the location of the clip file

Return value

Boolean: true if successful

SetAutoPaste

Description

Sets the status of the AutoPaste flag. Note: This command will no longer change the user preference.

Parameters

Boolean

SetClip

Description

Sets the clipboard and the currently loaded clip to the contents

Parameters

Text: the XML code of the clip to set

SetClipContents

Description

Sets the currently loaded clip to the contents, but don't set it in the clipboard.

Note: Available since build 4.0.1.906

Parameters

Text: the XML code of the clip to set

Return Value

Boolean

SetCurrentClip

Description

Sets the loaded clip in the clipboard.

Note: Available since build 4.0.1.906

Return Value

Boolean

SetReplaceOptionRegEx

Description

Set the replace option RegEx to true or false. Note: This command will no longer change the user preference.

Parameters

Boolean

SetReplaceOptionRegExGreedy

Description

Greedy means the search finds everything from the beginning of the first delimiter to end of the last delimiter and everything in-between. Note: This command will no longer change the user preference.

Parameters

Boolean

SetReplaceOptionRegExDotMatch

Description

Normally the period matches everything except a new line, this option allows it to match new lines. Note: This command will no longer change the user preference.

Parameters

Boolean

SetReplaceOptionRegExOneLine

Description

Ignores internal newlines for purposes of matching against '^' and '$'. Note: This command will no longer change the user preference.

Parameters

Boolean

SetReplaceOptionMatchEntireWord

Description

This option is not supported and will be ignored. Note: This command will no longer change the user preference.

Parameters

Boolean

SetReplaceOptionCaseSensitive

Description

Case Sensitive search Note: This command will no longer change the user preference.

Parameters

Boolean

SetReplaceOptionReset

Set all Replace Options to False. Note: This command will no longer change the user preference.

Parameters

Boolean

Obsolete Commands

All AppleScript commands are no longer making use of the clip in memory, except for these mentioned in the "Obsolete" section. This commands will still working, but we recommend you to avoid them.

CopyFromClipContentsField

Description

Copy the contents of the XML editor in the Clip Manager window to the clipboard. The function will copy the last legal XML version. The function will not copy an illegal XML.

GetClipContentsField

Description

Get the contents of the XML editor in the Clip Manager window. The function will return the last legal XML version. The function will not return an illegal XML.

Return value

Text: the contents of the field (should be UTF-8 text)

isXMLValid

Description

Returns if the loaded clip is valid xml or not. Since the XML of a loaded clip is always valid in Clip Manager 4, this command will always return true. If there is no clip loaded the function will return a false.

Return value

Boolean: True

PasteToClipContentsField

Description

Paste the the unicode contents of the clipboard to the XML editor in the Clip Manager window. The function will not check the content.

SetClipContentsField

Description

Set the contents of the clip contents xml editor with the passed unicode string of the current clip. The function will not check the content.

Parameters

Text: the XML code of the clip to set.

Examples

Set Clip

SetClip Example 1

set theClipXML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><fmxmlsnippet type=\"FMObjectList\">" & ¬
	"<Field id=\"32811\" dataType=\"Date\" fieldType=\"Normal\" name=\"Date_Created\"><Comment/>" & ¬
	"<AutoEnter allowEditing=\"False\" value=\"CreationDate\" constant=\"False\" furigana=\"False\" lookup=\"False\"" & ¬
	" calculation=\"False\"><ConstantData/></AutoEnter><Validation message=\"False\" maxLength=\"False\"" & ¬
	" valuelist=\"False\" calculation=\"False\" alwaysValidateCalculation=\"False\" type=\"OnlyDuringDataEntry\">" & ¬
	"<NotEmpty value=\"False\"/><Unique value=\"False\"/><Existing value=\"False\"/><StrictValidation value=\"False\"/>" & ¬
	"</Validation><Storage autoIndex=\"True\" index=\"None\" indexLanguage=\"English\" global=\"False\" maxRepetition=\"1\"/></Field>" & ¬
	"<Field id=\"32811\" dataType=\"Date\" fieldType=\"Normal\" name=\"Date_Modified\"><Comment/>" & ¬
	"<AutoEnter allowEditing=\"False\" value=\"ModificationDate\" constant=\"False\" furigana=\"False\" lookup=\"False\"" & ¬
	" calculation=\"False\"><ConstantData/></AutoEnter><Validation message=\"False\" maxLength=\"False\"" & ¬
	" valuelist=\"False\" calculation=\"False\" alwaysValidateCalculation=\"False\" type=\"OnlyDuringDataEntry\">" & ¬
	"<NotEmpty value=\"False\"/><Unique value=\"False\"/><Existing value=\"False\"/><StrictValidation value=\"False\"/>" & ¬
	"</Validation><Storage autoIndex=\"True\" index=\"None\" indexLanguage=\"English\" global=\"False\" maxRepetition=\"1\"/></Field>" & ¬
	"</fmxmlsnippet>"
tell application "Clip Manager 5"
	SetClip theClipXML
end tell

the clipboard

This AppleScript code assigns a string with XML code to the variable theClipXML. The text string looks a bit strange, this is because it has to be quoted for literal use in the code.

It then asks Clip Manager to put it on the clipboard as a FileMaker clip.

Finally, with the instruction "the clipboard" we ask AppleScript to show us the clipboard as the result.

It should look like this:

"Date_Created	Date	Creation Date, Can't Modify Auto
Date_Modified	Date	Modification Date, Can't Modify Auto"

The clipboard also contains a chunk that FileMaker will understand as 2 fields, but AppleScript wil only show us the text part of the clipboard.

SetClip Example 2

set theClipXML to "set theClipXML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><fmxmlsnippet type=\"FMObjectList\">" & ¬
	"<Step enable=\"True\" id=\"68\" name=\"If\" clipID=\"140828\"><Calculation>1</Calculation></Step>" & ¬
	"<Step enable=\"True\" id=\"45\" name=\"Undo/Redo\" clipID=\"351340\"><UndoRedo value=\"Toggle\"/></Step>" & ¬
	"<Step enable=\"True\" id=\"69\" name=\"Else\" clipID=\"472803\"/>" & ¬
	"<Step enable=\"True\" id=\"48\" name=\"Paste\" clipID=\"545062\"><NoStyle state=\"False\"/><SelectAll state=\"True\"/><LinkAvail state=\"False\"/></Step>" & ¬
	"</fmxmlsnippet>"

tell application "Clip Manager 5" to SetClip theClipXML

the clipboard"

We're doing the same thing here, but this time with some script XML. The clipboard should look like this now:

"If [1]
	Undo/Redo [Toggle]
Else
	Paste [Select]"

Notice that Clip Manager did its best to indent the text represention of the 4 scriptlines it put on the clipboard.

Go to FileMaker and paste into a new script to see if it works for you.

Personal tools