schedule()
Schedules a task to run repeatedly based on a cron expression. Perfect for recurring automations like posting content, checking notifications, or performing maintenance.string
required
JavaScript code to execute. Can be a single statement or a function call.
string
required
Cron expression defining when the task runs. Format:
second minute hour day month dayOfWeekvoid
The task is registered and will run according to the schedule.
Basic Usage
Cron Expression Format
Cron expressions use 6 fields:Common Cron Patterns
Every N minutes
Every N minutes
Every N hours
Every N hours
Specific times
Specific times
Complex patterns
Complex patterns
Practical Examples
Implementation Details
Source Location
MainActivity.kt:5488
Task Storage
Scheduled tasks are:- Persisted to SharedPreferences
- Survive app restarts
- Checked by a background cron checker thread
- Assigned unique IDs for management
Tasks execute on a scheduled executor service with 2 threads. Long-running tasks should be avoided.
clearSchedule()
Removes all scheduled tasks. Useful for resetting automation state or clearing old schedules.void
All scheduled tasks are cleared and removed from storage.
Usage
Implementation
MainActivity.kt:5525
Complete Examples
Instagram Posting Bot
Email Digest
Status Checker
Best Practices
Keep task code simple
Keep task code simple
Scheduled tasks should call functions rather than containing complex inline code.
Include error handling in scheduled functions
Include error handling in scheduled functions
Errors in scheduled tasks should be caught and handled gracefully.
Avoid scheduling too frequently
Avoid scheduling too frequently
Very frequent tasks (every second) can drain battery and CPU.
Clear old schedules before creating new ones
Clear old schedules before creating new ones
Prevent duplicate tasks by clearing before scheduling.
Viewing Scheduled Tasks
Scheduled tasks appear in the PhoneClaw UI:- Open the PhoneClaw app
- Navigate to the Scheduled Tasks tab
- View all active tasks with their cron expressions
- See last execution time and next scheduled time
Limitations
Related Functions
- delay() - Add delays within scheduled tasks
- speakText() - Announce scheduled task execution
- sendAgentEmail() - Send notifications from scheduled tasks