OK Script Tasks
Overview
Use this skill to create or modify tasks built on the PyPI ok-script library. Keep guidance generic to ok-script; inspect the current project only to discover its local base classes, scene helpers, feature names, and registration style.
When more detail is needed, read:
references/task-api.mdfor task lifecycle, config, execution, GUI, and bilingual rules.references/templates.mdfor reusable one-time task, trigger task, feature/OCR, and registration templates.- Use
$ok-script-i18nafter task creation when gettext catalogs need task strings added, synced, or compiled.
Workflow
- Inspect the target project for existing tasks, app config, and any project-specific base class.
Prefer existing project helpers over inheriting directly from
BaseTaskwhen the project already has a base task class. - Decide the task type:
- Use
BaseTaskor a project one-time base for user-started workflows that should finish and disable themselves. - Use
TriggerTaskfor background checks that run repeatedly while enabled. - Mix in feature/OCR/project helpers only when the task actually needs them.
- Use
- Add or update task metadata in
__init__:name,description,default_config,config_description,config_type,supported_languages, icons, grouping, and scheduling flags. - Implement
run()with small, observable steps. Useself.log_info,self.log_warning,self.info_set,self.wait_until,self.next_frame,self.sleep,self.click_relative,self.find_one,self.wait_click_feature,self.ocr, andself.wait_ocrinstead of ad hoc polling or direct device calls. - Register the task according to the project style:
built-in config list,
ok_taskscustom task folder, or imported script package. - If the project uses gettext catalogs, sync task translations with
$ok-script-i18n. - Validate with the project test or headless path when available. At minimum, import the task module and instantiate the class if device-dependent execution cannot be run.
Bilingual Output
Support English and Chinese in both code review and generated code.
- Answer the user in the language they use. If unclear, use English with concise Chinese labels where useful.
- Prefer stable English config keys because config keys become persisted JSON fields. Add Chinese help in
config_descriptionor through the project's translation system. - Include both English and Chinese OCR match text when the UI may appear in either language.
- Use
supported_languagesonly to hide a task in unsupported locales. Common locale names areen_US,zh_CN,zh_TW,ja_JP,ko_KR, andes_ES. - Do not hard-code assumptions from the source project used to study
ok-scriptunless the target project explicitly uses them.
Essential Rules
- Always call
super().__init__(*args, **kwargs)before setting task fields. - Do not bypass
Config: set defaults inself.default_config; read values throughself.config.get(...)afterafter_init()loads config. - For
TriggerTask, keepself.default_config['_enabled']intentional and settrigger_intervalto avoid excessive polling. - Return truthy from a trigger task only after it handled something meaningful; falsey return lets the executor continue scanning other trigger tasks.
- For one-time tasks, allow normal completion; the executor disables the task after
run()returns. - Keep direct sleeps short and use
wait_until,wait_ocr, orwait_click_featurefor state-dependent waiting. - Avoid locale-specific config keys unless the project already follows that style.