中文

What is Surroga?

Surroga is a keyboard & mouse automation utility for macOS. It can automate every thing you can do with your Mac, even iPhone.

Surroga can be downloaded on AppStore. We continue to make Surroga the best automation utility ever to fit you needs. We need you help to shape the future direction of new features and improvements. If you have any comments about Surroga, please feel free to let us know. , we will reply every feedback email.

Content

What is Surroga?

Surroga is a keyboard & mouse automation utility for macOS.
Tips: The app will need ask for "Accessibility" permission at the "Privacy & Security" at the System Settings.

Content

Script

Record Script

Surrga can record user operations in the specified window.

The new recorded script will appear in the script list at the left sidebar.

Content

Remove Script

To remove a script, select it via the script list at left sidebar, then press the DELETE key on the keyboard. Or, click the script via the mouse right button, the click the Delete option in the context menu.

Export & Share

Select a script, then click Export, choice Share or Share as Protected. The protected script is not editable, and will not create the logs.

Export

Import a script.

Import

Content

Statement

Statement group expressions and control the flow of execution.

Insert, Sort, Remove a Statement

Insert a Statement

Click on + on the toolbar in the navigation bar of the script editor, select and add a new statement at the end of the script. If you want to insert the new statement at the specified statement, you can right-click on that statement to invoke the context menu, and then select New.

Sort Statements

Reorder statements with simple drag & drop.

Delete a Statement

In the script editor, click a statement via the mouse right button, the click the Delete option in the context menu.

Tips: Don't click in the textfield. Or else, the context menu is not include the Delete item.

Content

Error Handling

When a statement encounters an error, we can specify how to handle it.

Error Handling

Content

Control Flow

If, Then, Else

'If', 'Then', and 'Else' are collectively referred to as 'conditional statements'.

Conditional Statements

By default, one statement include only one action. When a statement is executed, this action will be executed.

On the other side, we can insert an IF sub-statement into a statement. The IF sub-statement is consist of one or more Conditions . The action of the statement, so called THEN sub-statement, will be executed only when conditions are true. If Conditions are false, this statement can be skiped, or execute the action in the ELSE sub-statement.

AND, OR

There are two combination types that be used between multiple conditions in the same statement.

When a statement contains multiple conditions, we can setup their combination type:

Condition Combination

Tips: Only one combination type can be used between multiple conditions in the same statement. In other words, all conditions contained in a statement must either be AND conditions or OR conditions.

Content

Loop

Surroga doesn't support LOOP statement yet. Instead, it use multiple methods to implement flexible loop.

Script Repeating

Repeating at script level by Repeat-limited, Repeat-infinite, Repeat-until or While-Do.

To initialize a loop, consider two scripts, main and sub-script. In the main script, we initialize the variable name VAR by assign a value(1) to it before call the sub-script. In the sub-script, it increase the VAR by 1 each time, and repeat until VAR is greater than 5. Surroga ship with a on-board script named "Counting". To view the results of this script, open a window that support text inpurt (typing keys), the click the system status bar -> Surroga -> Run -> General -> Counting.

Continue Statement

Bypass the remainng statements in the current script, move on to the beginning of the current script, re-execute the current script from the beginning.

In Surroga, the Continue statement is implemented as a statement containing one or more conditions and a Continue action, and is usually used to perform script-level loops under specific conditions.

Content

Call

Call another script. At this time, the caller is often referred to as the parent script. The called script is referred to as the child script.

NB! Surroga allows scripts to have the same name. Therefore, when calling another script, one should be careful not to mistakenly call an unrelated script with the same name, especially when a user-defined script has the same name as a built-in script of Surroga.

Return

RETURN statement will abort the current script, and return to its parent script (the caller).

RETURN statement doesn't returns any value to its parent script. Instead, if we want to do this, assign the value to one of variables before return, then read the value of the variable in the parent script. In Surroga, the scope of variables are global. Variables are shared by all scripts.

In Surroga, it is implemented as an action.

Exit

EXIT, also called ABORT, END or STOP statement. This statement only only abort the running of the current script, but also its parent script, ..., parent of parent. Finally, it abort the 'Root' script.

In Surroga, it is implemented as an action.

Content

Condition

Window Pixel Color Is Similar

Get the pixel color at a specified position in the window and compare it with a specified color. If they are similar, it is judged to be true. Otherwise, it is judged to be false.

NB! This condition includes several hidden conditions. If the window screenshot fails, or if the pixel position is incorrect, or if they do not match, then the result is determined to be false.
NB! If you need to compare the colors of multiple pixels in a window at the same time, it is recommended to take a screenshot of the window first, and then perform 'color comparison from the image', that is, compare these pixels within the captured image content, which will be more efficient.

Color Is Similar

If both items being compared are colors and are similar, then it is judged to be true. Otherwise, it is judged to be false.

NB! This condition includes a hidden condition "both must be colors". If either one is not a color (especially when the variable content is being compared), then the result is judged to be false.

Image Is Similar

If both items being compared are images and are similar, then it is judged as true. Otherwise, it is judged as false.

NB! This condition includes a hidden condition "both must be images". If either one is not a image (especially when the variable content is being compared), then the result is judged to be false.

Image Contains Text

If the image specified by the former contains the text specified by the latter, then it is judged to be true. Otherwise, it is judged to be false.

NB! This condition includes the hidden condition "the former is an image." If the former is not an image (especially when the comparison is with variable content), the judgment result will be false.

Content

Actions

Keystroke

Type a single keystroke, pretty much any kind of keystroke you can type on the keyboard.

How to specify the key

To specify the desired key to press, open the action editor, expand the action details, and click the key specified by the action with the mouse; that key will be highlighted. Then press a key on the hardware keyboard. The editor will record the pressed key and assign it as the key for that action.

Keystroke

Tips: The macOS keyboard shortcuts can not be recorded. For example, Option–VolumeDecrease on Apple Keyboard, or Alt–F11 on Windows keyboards:

Therefore, Surroga provides some pre-made key actions to insert them. If you find that Surroga can not support inserting a certain specific key combination, please .

Hardware Assisted

For certain special scenarios or specific applications, special dedicated hardware is required to assist with keyboard operations. At this time, the Hardware Assist option needs to be enabled in the action editor. For example, due to macOS system features, the action of 'simulating pressing the F11 key' can only work properly when hardware assistance is enabled.

Hardware Assisted Keystroke Hardware Assisted
Tips: This option appear only if Expert Mode is enabled.

Content

Typing Text

Continuously press a series of keys on the physical keyboard in the predetermined order and speed to automatically input a piece of text.

Tips: This text must be consist of keys on the hardware keyboard. No all languages are supported, e.g. Chinese.
Tips: Some editable text area do not support the Shift key, which can cause uppercase letters to become lowercase.
Tips: Before take this action, please make sure that the target window has been opened/activated already, and focused on the editable text area. Or else, these key-strokes will be ignored by macOS.

Hardware Assisted

For certain special scenarios or specific applications, special dedicated hardware is required to assist with keyboard operations. At this time, the Hardware Assist option needs to be enabled in the action editor (Tip: You must enable Expert Mode first to see this option).

Content

Mouse Operations

Move the mouse cursor, click the mouse button, or dragging.

Move the mouse cursor to

Click the mouse button at the calculated position.

Tips: Before move the mouse cursor or click the mouse button in the window, please make sure the window is already open and bring to front. See also: Open Application Action.
Tips: If you want to operate a certain app on your iPhone through iPhone Mirroring, please set the app window to iPhone Mirroring instead of the target app.
Tips: When using absolute positioning (screen positioning) instead of (window-)relative positioning, especially when positioning the center of the screen, only the primary screen is supported, and secondary screens are not supported.
Tips: In macOS 15 or earlier, simulated mouse clicks may not work for certain applications. This is because these applications deliberately block automation tools. They use special low-level mechanisms that ignore mouse and keyboard simulation actions sent by automation tools. Upgrading macOS to the latest version (for example, 26.3.1) can resolve this issue.

Similarity

In the process of searching for images and colors, Surroga will calculate the similarity between each 'suspected' object and the target object. If the similarity is greater than the specified threshold, the match is successful.

Therefore, in operations like searching for images or colors, the higher the similarity parameter, the more similar the found objects are to the target object, but the less results. If a mismatch result is found, it is recommended to raise the similarity threshold. If nothing can be found, it is suggested to lower the similarity threshold.

Tips: The real color on iPhone/iPad/Mac may be dynamic according to current system appearance (dark or light), zoom ratio of iPhone Mirroring window. So, the color parameter of the Click-Color action must fit the real environment.

Locate the Subimage

To accelerate the image recognizing,

Tips: If the subgraph is a foreground object with an irregular contour, its exposure to the background should be minimized.

Incorrect example: As the target prospect being searched for, the tile reveals the background image underneath.

Bad Example

Correct example: As the target to be searched, it only contains the pixels of the foreground object, without revealing the background image.

Good Example

Special case: As a foreground target to be searched, its filled content lacks uniqueness and can only rely on shape to differentiate the target object from interference objects. If the background color may change, you can use 'Replace Color in Image' for preprocessing to keep the background color consistent.

find subimage by shape

Extra Match

When performing mouse operations on text and images, in order to handle cases where the window contains multiple target objects (texts, images), some additional matching criteria can be used to filter out irrelevant targets. For example, we may require that the target object is nearby another specified text or image.

Click Text Nearby Text

As shown in the figure above, we want to click on green 'Coordinates', but there are three instances of 'Coordinates' in the image. To eliminate interference, we can set it to only click on the 'Coordinates' that is near the 'Screen'.

Scattered

Once the target point is specified or found, use that point as the base point. Generate a randomly offset point around the base point. The maximum distance between the offset point and the base point should not exceed the scatter radius. Example: randomly click near the coordinates (500, 500).

This feature is used to simulate the randomness of mouse operations by human.

随机散布

Content

Wait

Surroga supports flexible and diverse wait actions.

Tips: When waiting for a fixed duration, if you find that the actual waiting time far exceeds the preset value, it is usually because the macOS 'App Nap' mechanism has been triggered. To resolve this issue, please refer to macOS App Nap.

Content

Screenshot

Take a screenshot of screen or window.

We can specify the content to capture:

To specify an region (portion of screen or window), you need to define the position and size of that region. The origin is at the top left corner of the screen or window. When specifying a screen region, what is specified is the absolute position of that region on the screen. When specifying a window region, what is specified is the relative position of that region within the window. For a region which size is (100,100):

Tips: The action will need ask for "Screen & System Audio Recording" permission at the "Privacy & Security" at the System Settings.
Tips: When a window is in the foreground and background state, its displayed content often varies. It is recommended to open the application before taking a screenshot of the window, ensuring it is in the foreground.

Window Title

The most macOS app shows more than one windows at the same time. For example, if we click the about option of an app, this app will shows at least two windows, the main window and the about window. For Safari, every Tab own its window. We can specify the Window Title to distinguish these windows. For Safari, the window title, in most cases, is the title of Tab.

Tips: For Safari, if we specify the title of the window, in others words, the title of the Tab, this Tab MUST be the current Tab of Safari. Or lese, the script will report 'Window Not Found'."

Content

Recognize Text

Recognize text from image or content in window.

Obviously, it's possible for an image to contain more than one piece of text. So, the results of recognizing-text is array of text, instead of just one text in a basic variable. For example, for an image that only contains a number, 32, this actions returns the array ["32"]. Then, use Get the First Element in Array action to get 32

Tips: DON'T look the text recognition results in the variable as a basic string, specially when the image contains only one word.

The result of recognization may be different according to recognization language. For example, if we setup the recognization language to English, it can not recognize Chinese in the content.

Tips: If the action 'Recognize text' can successfully recognize text, but the condition 'Text contained in images/windows' cannot recognize the same text, it may be because the languages set in these two cases are different.

Content

Text to Speech

Text-to-Speech (TTS) can produces synthesized speech from text in various languages, thereby supporting automated voice control, making it particularly suitable for scenarios that require voice control (such as certain iPhone applications).

TTS
Tips: If the language does not match the actual language of the text (for example, setting the language to English while the text is actually in Chinese), it may not be able to read the text correctly.

Content

Calculate Coordinates

There is a set of actions specifically used to calculate 2D coordinate points. In these actions, variables are used to store a 2D coordinate point, also known as a coordinate point variable.

Tips: Users can use the assignment action to manually initialize a coordinate point variable, for example, var1 = "(1, 2)"。
Tips: When simulating mouse operations (clicking, moving, dragging), you can use coordinate variables to specify positions, thereby offering great flexibility.

Content

Popup Alert

Pop-up a modal dialog to show something or input something.

Popup Alert
Tips: There is only one model dialog can appear on screen at the same time. If more than one actions are executed to pop-up dialogs, only the first one will appear.

Send Notification

Send a local notification that showed on the current device. Notifications are used to show the status of running script, or notify users to do necessary operations.

Send Notification
Tips: This action just request the Mac for the notification. There is no guarantee that the notification will be showed. Please visit Apple Mac User Guide for more infomation.

Content

Log

This action will print a log message. The log entry will appear in the log window on the left sidebar or in the log file (if file logging is enabled).

When displayed in the left sidebar window, log entries of different levels are shown in different colors, making them more noticeable. This parameter does not apply to file logs.

Content

HUD

Head Up Display, HUD, overlays text or images on the main screen.

HUD

Tips: We can use this feature to overlay some auxiliary information on the screen. For example, use HUD text to show the number of battles, the number of victories, and the total number of coins collected, use HUD rectangle to show a process bar.

Content

Save as File

This action is used to save the content of the variable to a file.

Files were saved into the documents directory in the Surroga sandbox. To view these files, click the Surroga icon on the system status bar, then click Open Documents on the menu.

Open Saved Files

Content

Load from File

Read the contents of a file and assign it to a (basic) variable.

If you want to read an array or dictionary from a file, you can first read the JSON text into a basic variable and then perform the action of Text to Array or Text to Dictionary to decode from JSON.

This action access the files in the documents directory in the Surroga sandbox.

Content

Open Application

This action is used to open an application. The application can be pre-selected or specified through a variable.

Tips: Due to macOS feature, if the application is already running and it has a system-level dialog open (such as the 'Open File' dialog), this action may not be able to bring the application (or dialog) directly to the foreground. Some additional statements are needed to identify the current situation and respond accordingly.

Variables

A variable is a container that used to store content such as text, number, or image. Variables will make your scripts more powerful and flexible.

Tips: Please switch to Expert Mode before using variables.

There are three kinds of variables are supported in Surroga. They are Variable, Array & Dictionary.

Tips: When operating on variables, if the data type of the variable does not match the expected, the script will fail. For example, when comparing whether two images are similar, we expect both of two variables store an image. If one of them stored is a number, the comparison will fail.

Scope

In Surroga, the scope of variables are global. Variables are shared by all scripts.

Therefore, to returns a value to its parent script, assign the value to one of variables before return, then read the value of the variable in the parent script.

Tips: Because variables are shared by all scripts, we must be careful to avoid interference between the scripts.

Content

(Basic) Variable

Basic variables also called general-purpose variables.

They are used to store images, text and text-based values, such as:

Pasteboard

In Surroga, the pasteboard is ofen used as the special variable. Using the clipboard is more convenient than using regular variables in most cases, especially when users are developing and debugging scripts, as they can easily observe the execution status of the current step. However, for a released script, we should still avoid using the clipboard and instead use regular variables.

User-defined Variables

In addition to built-in variables, users can also create and name their own variables, commonly referred to as user-defined variables, custom variables or named variables.

User variables are all basic variables, accessed by name. For example,

Content

Array

Array is an ordered series of elements.

Content

Dictionary

Dictionary is a collection whose elements are key-value pairs.

Content

Examples

Let's discusses some common approaches to script writing.

Monitoring

Suppose there is an application scenario that monitors a certain area on the screen. If this area changes to the preset image A, the custom key '1' on the keyboard is pressed. If this area changes to the preset image B, the custom key '2' on the keyboard is pressed.

The above requirements can refer to the following logical flow.

Set the script to an infinite loop, which contains the following process:

Among them, image A and B can be obtained by taking screenshots.

The above script is simple enough and very suitable for beginners. However, it hides too many details. If the execution result is not as expected, it is difficult to observe which step went wrong. To address this, we can try to break down the steps and rewrite them in the following form:

Then, enable expert mode, open the log interface in the right sidebar, run the script, and observe the execution process.

Content

Paste Text to another App

How can I copy specific text into the text input box of another application window?

First, copy the specified text to the clipboard. Then open another application and focus on the text input box. Finally, use the paste action. The steps are as follows:

Tips:Some input fields do not support pasting. In this case, you can switch to 'Keyboard > Type Text (Variable)'. Some input fields do not support the Shift key, which causes uppercase letters to turn into lowercase. Some input fields do not support software simulation. In such cases, special methods can be used. Therefore, it is still necessary to analyze each case specifically. In principle, perform the manual operation first and ensure it is successful, and then simulate this manual operation.

Content

Log

There are two types of logs in the Surroga: memory logs and file logs.

Log Settings

Memory Log

Right Side Bar

File Log

Tips: If you notice that your Mac's storage is being used up quickly after running scripts for a long time, you can check whether file logging is enabled. If you find that file logs are consuming a large amount of storage, you can click the 'Clean' button and turn off file logging.

Content

Performance

Disable Logs

Disable Log and File Log to improve the script performance.

Optimize for Screenshot

There are some tips to optimize the performance when capture screen content.

Optimize for Recognizing

There are some tips to optimize the performance of recognizing content. For example, when recognize text, click/move/drag on text, recognize barcodes or qrcodes.

Find Subimage or Color

When searching for sub-images or colors in a window or picture, try to output only the first result instead of the best result, all results, or the top 10 results, in order to avoid significant overhead.

Prevent App Nap

'App Nap' is a feature in macOS that puts an application into a 'sleep lightly' state when it is running in the background and not visible, especially after a long period of inactivity with that application. This reduces CPU usage and resource consumption. The mechanism is designed to save power and improve system performance. At the same time, it can also enhance the performance of foreground applications, thereby optimizing the user experience for active apps.

However, since Surroga needs to run in the background with high performance for long periods (for example, monitoring the content changes of a window in real-time), 'App Nap' feature can also severely reduce Surroga's performance. Therefore, we must prevent it from entering a nap state.

To do this, we can minimize the Surroga window (rather than just letting it be covered by other windows).

Content

Expert Mode

Surroga supports two work modes.

Open Surroga > Settings > Advanced, switch between Beginner and Expert.

Advanced Mode

Tips: When you can't find the feature you want, please try turning on Expert Mode.

Content

Multi-Display

Surroga is designed to work on the main screen.

Although Surroga does not support multiple displays, it works well in most cases, especially when the target object is draw on the primary display, or when using window-positioning instead of screen-positioning. If you suspect that multi-display mode is interfering with Surroga's ability to locate target objects on the screen, you can try removing the secondary display.

Multi-Displays

Content

Background Task

Surroga is designed to simulate foreground manual operations, so it does not support running in the background, nor does it transmit network data.

In-App Purchases

Paid Features

Paid features include:

For example, when insert a new action into script, some actions in the candidate action list are disabled for picking. It means these actions are paid features. They will be unlocked after payment.

Non-Consumable vs. Subscription

Monthly-Subscription, Yearly-Subscription and Pro shared the same features but payment. All of three unlock all features. Subscriptions are for monthly or yearly. Pro is lifetime.

Activate

Still locked after payment?

Surroga embedded a built-in mini shop provided by Apple. This mini shop is fully maintained by Apple. If the payment was completed, Apple should tell the application on network available. But, if Apple is not, for network issues or AppStore backend malfunctions.

Apple Service Status

There are some sugguestions below:

Tips: Each time you run it, an internet connection is required for activation. When App Store occasionally malfunctions due to a very small probability, activation may be slow or fail. In this case, please wait for a moment or restart the application.

Content

Privacy & Security

Surroga can perform lots of tasks of applications and control your Mac. As such, it needs your security permissions to do these jobs for you. These permissions may vary according to different macOS versions. In most cases, the app will need ask for these permissions at the Privacy & Security at the System Settings.

Privacy & Security

As shown in the above figure, if both items in the image are displayed in green, it indicates that this application has been granted system authorization.

Accessibility

Allows control of your mouse and keyboard, and monitoring your mouse and keystrokes. It is required for following app features:

Screen Recording

Allows capture the screen. It is used for following app features:

Content

Privacy Statement

Data Not Collected.

The developer does not collect any data from this app.

Which app features will use screen recording?

Accessibility and Screen Recording permissions are needed to implement the essensial features of this app. The storken keys or screenshots are automated by the user's own, and never send to the developer. Please visit Privacy & Security for more infomation.

What data does your app collect via screen recording?

The data, user-specified image or text, was recorded by the user's own willing. No data was collected by this app or the developer.

For what purposes are you collecting this information? What plan for uses of this data.

No data was collected by the developer. No plan to use.

Will the data be shared with any third parties?

No.

Where will this information be stored?

This information was stored in device RAM. It will lost if app quit, or device shutdown/reboot. If the users choice output the data to system pasteboard, then they can visit macOS system instead of this app.

Content